search

Home  >  Q&A  >  body text

c++ - Qt connect function reports error?


#include <QObject>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addDialog.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

ui->setupUi(this);
setFixedSize(this->width(), this->height());
addDialog addD();
editDialog editD();
QObject::connect(&editD, &editDialog::sendData,
                 this, &MainWindow::get_data_from_edit);
    QObject::connect(&addD, &addDialog::sendData,
                     this, &MainWindow::get_data_from_add);
}

Both connections reported errors

error: no matching function for call to 'MainWindow::connect(editDialog (*)(), void (editDialog::*)(QString), MainWindow*, void (MainWindow::*)(QString))'
                      this, &MainWindow::get_data_from_edit);
                                                           ^
In file included from D:\QT.9\mingw53_32\include\QtCore/QObject:1:0,
                 from mainwindow.cpp:3:

error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'

All classes used inherit QObject and contain Q_OBJECT

Using the old syntax still reports an error

高洛峰高洛峰2724 days ago1323

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-06-19 09:09:26

    addDialog addD();
    editDialog editD();
    Are these two sentences instances of two objects? Try removing ().

    reply
    0
  • 某草草

    某草草2017-06-19 09:09:26

    Owner, please post the method declarations of MainWindow::get_data_from_edit and MainWindow::get_data_from_add.

    reply
    0
  • Cancelreply