Qt connect函数报错?


#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);
}

两个connect都报错

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\5.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>'

所使用类均继承QObject并包含Q_OBJECT

使用旧语法仍然报错

阅读 6.8k
2 个回答
新手上路,请多包涵

addDialog addD();
editDialog editD();
这两句是实例2个对象嘛?把()去掉试试。

楼主,你把MainWindow::get_data_from_edit和MainWindow::get_data_from_add的方法声明贴出来。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题