gpt4 book ai didi

c++ - QWizard::addPage() 上的 "QObject::connect: Attempt to bind non-signal Class::signal"警告

转载 作者:行者123 更新时间:2023-11-30 05:01:40 26 4
gpt4 key购买 nike

当尝试在派生 QWizard 的构造函数中添加带有自定义 Q_PROPERTY 的派生 QWizardPage 时,我收到以下针对我的最小示例的运行时警告:

QObject::connect: Attempt to bind non-signal TreeView::ndex_changed [sic]

在我原来的项目中,字段“index”仍然按预期工作,所以我提供了一个只发出警告的示例。我怎样才能摆脱这个警告?

我正在使用 Qt 5.10.1 和 gcc 5.3.0 (MinGW)。


最小示例

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets)
project(QWizard)
add_executable(${PROJECT_NAME}
main.cpp
TreeView.cpp
Wizard.cpp
WizardPage.cpp
)
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
)

主要.cpp

#include "Wizard.h"
#include <QApplication>

int main(int argc, char *argv[]) {
QApplication application{argc, argv};
Wizard wizard{};
wizard.show();
return application.exec();
}

TreeView .h

#pragma once

#include <QTreeView>

class TreeView : public QTreeView {
Q_OBJECT
Q_PROPERTY(QModelIndex index READ index NOTIFY index_changed)

public:
explicit TreeView(QWidget* parent = nullptr);

QModelIndex index() const;

signals:
void index_changed();
};

TreeView .cpp

#include "TreeView.h"

TreeView::TreeView(QWidget *parent) : QTreeView(parent) {
connect(this, &QTreeView::clicked, [&]() { emit index_changed(); });
}

QModelIndex TreeView::index() const { return currentIndex(); }

向导.h

#pragma once

#include <QWizard>

class Wizard : public QWizard {
public:
explicit Wizard(QWidget* parent = nullptr);
};

向导.cpp

#include "Wizard.h"
#include "WizardPage.h"

Wizard::Wizard(QWidget *parent) : QWizard(parent) {
auto *page = new WizardPage{this};
addPage(page);
}

向导页.h

#pragma once

#include <QWizardPage>

class WizardPage : public QWizardPage {
public:
explicit WizardPage(QWidget* parent = nullptr);
};

向导页面.cpp

#include "WizardPage.h"
#include "TreeView.h"
#include <QVBoxLayout>

WizardPage::WizardPage(QWidget *parent) : QWizardPage(parent) {
auto *tree_view = new TreeView{this};
registerField("index*", tree_view, "index", "index_changed");
auto *layout = new QVBoxLayout{this};
layout->addWidget(tree_view);
setLayout(layout);
}

最佳答案

我认为在 registerField() 中你应该使用 SIGNAL(index_changed()) 而不是 "index_changed"

它给出了以下对 registerField()

的调用
registerField("index*", tree_view, "index", SIGNAL(index_changed()));

关于c++ - QWizard::addPage() 上的 "QObject::connect: Attempt to bind non-signal Class::signal"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50192010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com