PMMA
PMMA

Reputation: 35

"QObject::connect: Attempt to bind non-signal Class::signal" warning on QWizard::addPage()

When trying to add a derived QWizardPage with a custom Q_PROPERTY in the constructor of a derived QWizard I get the following runtime warning for my minimal example:

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

In my original project the field "index" still works as expected, so I've provided an example which only emits the warning. How can I get rid of this warning?

I'm using Qt 5.10.1 and gcc 5.3.0 (MinGW).


Minimal example

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
)

main.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(); }

Wizard.h

#pragma once

#include <QWizard>

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

Wizard.cpp

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

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

WizardPage.h

#pragma once

#include <QWizardPage>

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

WizardPage.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);
}

Upvotes: 1

Views: 1232

Answers (1)

benjarobin
benjarobin

Reputation: 4487

I think in registerField() you should use SIGNAL(index_changed()) instead of "index_changed"

Which gives the following call to registerField()

registerField("index*", tree_view, "index", SIGNAL(index_changed()));

Upvotes: 1

Related Questions