呼叫连接没有匹配功能-Qt 5.5

  • 本文关键字:功能 -Qt 连接 呼叫 c++ qt
  • 更新时间 :
  • 英文 :


在更新Signal/Slot函数时,我们会遇到未定义的问题。这是我们收到的错误:


这就是以前的情况,一切都很好,没有问题:

主窗口.cpp

connect(_restrict, &Restrict::windowChanged, _record, &Record::onWindowChanged);

主窗口.h:

private slots:
void onWindowChanged(QDateTime current, QString processName, QString windowTitle, QString url, long prevPID, long currPID);

record.h:

public slots:
void onWindowChanged(QDateTime time, QString processName, QString windowTitle, QString url, long prevPID, long currPid);

restrict.h:

signals:
void windowChanged(QDateTime time, QString processName, QString windowTitle, QString url = "", long prevPID = -1, long currPid = -1);

我们的数据更改后:

主窗口.cpp

connect(_restrict, &Restrict::windowChanged, _record, &Record::onWindowChanged);

主窗口.h:

private slots:
void onWindowChanged(QDateTime current, QString processName, QString windowTitle, QString url, long prevPID, long currPID, bool whitelisted);

record.h:

public slots:
void onWindowChanged(QDateTime time, QString processName, QString windowTitle, QString url, long prevPID, long currPid, bool whitelisted);

restrict.h:

signals:
void windowChanged(QDateTime time, QString processName, QString windowTitle, QString url = "", long prevPID = -1, long currPid = -1, bool whitelisted = false);

出现错误:

mainwindow.cpp:84:91: error: no matching function for call to 'MainWindow::connect(Restrict*&, void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool), Record*&, void (Record::*)(QDateTime, QString, QString, QString, long int, long int, bool))'
             connect(_restrict, &Restrict::windowChanged, _record, &Record::onWindowChanged);
                                                                                           ^
mainwindow.cpp:84:91: note: candidates are:
In file included from Qt5.5mingw492_32include/QtCore/qabstractanimation.h:37:0,
                 from Qt5.5mingw492_32include/QtCore/QtCore:4,
                 from Qt5.5mingw492_32include/QtWidgets/QtWidgetsDepends:3,
                 from Qt5.5mingw492_32includeQtWidgets/QtWidgets:3,
                 from mainwindow.cpp:1:
Qt5.5mingw492_32include/QtCore/qobject.h:196:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
     static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                    ^
Qt5.5mingw492_32include/QtCore/qobject.h:196:36: note:   no known conversion for argument 2 from 'void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool)' to 'const char*'
Qt5.5mingw492_32include/QtCore/qobject.h:199:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
     static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                    ^
Qt5.5mingw492_32include/QtCore/qobject.h:199:36: note:   no known conversion for argument 2 from 'void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool)' to 'const QMetaMethod&'
Qt5.5mingw492_32include/QtCore/qobject.h:475:32: note: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
 inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                ^
Qt5.5mingw492_32include/QtCore/qobject.h:475:32: note:   no known conversion for argument 2 from 'void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool)' to 'const char*'
Qt5.5mingw492_32include/QtCore/qobject.h:213:43: note: template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType)
     static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                           ^
Qt5.5mingw492_32include/QtCore/qobject.h:213:43: note:   template argument deduction/substitution failed:
Qt5.5mingw492_32include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool); Func2 = void (Record::*)(QDateTime, QString, QString, QString, long int, long int, bool)]':
mainwindow.cpp:84:91:   required from here
Qt5.5mingw492_32include/QtCore/qobject.h:213:43: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<void (Record::*)(QDateTime, QString, QString, QString, long int, long int, bool)>'
Qt5.5mingw492_32include/QtCore/qobject.h:245:13: note: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
             connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
             ^
Qt5.5mingw492_32include/QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
mainwindow.cpp:84:91: note:   candidate expects 3 arguments, 4 provided
             connect(_restrict, &Restrict::windowChanged, _record, &Record::onWindowChanged);
                                                                                           ^
In file included from Qt5.5mingw492_32include/QtCore/qabstractanimation.h:37:0,
                 from Qt5.5mingw492_32include/QtCore/QtCore:4,
                 from Qt5.5mingw492_32include/QtWidgets/QtWidgetsDepends:3,
                 from Qt5.5mingw492_32includeQtWidgets/QtWidgets:3,
                 from mainwindow.cpp:1:
Qt5.5mingw492_32include/QtCore/qobject.h:254:13: note: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
             connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
             ^
Qt5.5mingw492_32include/QtCore/qobject.h:254:13: note:   template argument deduction/substitution failed:
Qt5.5mingw492_32include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool); Func2 = void (Record::*)(QDateTime, QString, QString, QString, long int, long int, bool)]':
mainwindow.cpp:84:91:   required from here
Qt5.5mingw492_32include/QtCore/qobject.h:254:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
In file included from Qt5.5mingw492_32include/QtCore/qnamespace.h:37:0,
                 from Qt5.5mingw492_32include/QtCore/qobjectdefs.h:41,
                 from Qt5.5mingw492_32include/QtCore/qobject.h:40,
                 from Qt5.5mingw492_32include/QtCore/qabstractanimation.h:37,
                 from Qt5.5mingw492_32include/QtCore/QtCore:4,
                 from Qt5.5mingw492_32include/QtWidgets/QtWidgetsDepends:3,
                 from Qt5.5mingw492_32includeQtWidgets/QtWidgets:3,
                 from mainwindow.cpp:1:
Qt5.5mingw492_32include/QtCore/qglobal.h:1073:45: error: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
 template <bool B, typename T = void> struct QEnableIf;
                                             ^
In file included from Qt5.5mingw492_32include/QtCore/qabstractanimation.h:37:0,
                 from Qt5.5mingw492_32include/QtCore/QtCore:4,
                 from Qt5.5mingw492_32include/QtWidgets/QtWidgetsDepends:3,
                 from Qt5.5mingw492_32includeQtWidgets/QtWidgets:3,
                 from mainwindow.cpp:1:
Qt5.5mingw492_32include/QtCore/qobject.h:285:13: note: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
             connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
             ^
Qt5.5mingw492_32include/QtCore/qobject.h:285:13: note:   template argument deduction/substitution failed:
mainwindow.cpp:84:91: note:   candidate expects 3 arguments, 4 provided
             connect(_restrict, &Restrict::windowChanged, _record, &Record::onWindowChanged);
                                                                                           ^
In file included from Qt5.5mingw492_32include/QtCore/qabstractanimation.h:37:0,
                 from Qt5.5mingw492_32include/QtCore/QtCore:4,
                 from Qt5.5mingw492_32include/QtWidgets/QtWidgetsDepends:3,
                 from Qt5.5mingw492_32includeQtWidgets/QtWidgets:3,
                 from mainwindow.cpp:1:
Qt5.5mingw492_32include/QtCore/qobject.h:293:13: note: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
             connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
             ^
Qt5.5mingw492_32include/QtCore/qobject.h:293:13: note:   template argument deduction/substitution failed:
Qt5.5mingw492_32include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (Restrict::*)(QDateTime, QString, QString, QString, long int, long int, bool); Func2 = void (Record::*)(QDateTime, QString, QString, QString, long int, long int, bool)]':
mainwindow.cpp:84:91:   required from here

我们只添加了一个布尔值,将其添加到信号和相应的槽中,现在我们不知道为什么这突然不再起作用。

我在这一页上读到:http://doc.qt.io/qt-5/signalsandslots.html

"如果您的编译器不支持C++11可变模板,则只有当信号和插槽具有6个或更少的参数时,此语法才有效。"

在上面的语句中,"this syntax"是您正在使用的新连接语法。

看起来你的信号槽现在有7个参数。这可能是问题的潜在原因。

只是为了仔细检查,您可以使用旧的信号插槽连接语法(带有宏signal和slot的语法)。

使其在.pro文件中工作所需的更改:

CONFIG += c++11

最新更新