2015-12-02 95 views
3

當更新我們的信號/時隙功能時,我們遇到了未定義的問題。 這是錯誤,我們得到:呼叫連接沒有匹配功能 - Qt 5.5


這就是從前那樣,工作的所有罰款沒有問題:

Mainwindow.cpp

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

Mainwindow.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); 

我們更改後的數據:

Mainwindow.cpp

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

Mainwindow.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 \Qt\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37:0, 
       from \Qt\5.5\mingw492_32\include/QtCore/QtCore:4, 
       from \Qt\5.5\mingw492_32\include/QtWidgets/QtWidgetsDepends:3, 
       from \Qt\5.5\mingw492_32\include\QtWidgets/QtWidgets:3, 
       from \mainwindow.cpp:1: 
\Qt\5.5\mingw492_32\include/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, 
            ^
\Qt\5.5\mingw492_32\include/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*' 
\Qt\5.5\mingw492_32\include/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, 
            ^
\Qt\5.5\mingw492_32\include/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&' 
\Qt\5.5\mingw492_32\include/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, 
           ^
\Qt\5.5\mingw492_32\include/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*' 
\Qt\5.5\mingw492_32\include/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, 
             ^
\Qt\5.5\mingw492_32\include/QtCore/qobject.h:213:43: note: template argument deduction/substitution failed: 
\Qt\5.5\mingw492_32\include/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 
\Qt\5.5\mingw492_32\include/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)>' 
\Qt\5.5\mingw492_32\include/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) 
      ^
\Qt\5.5\mingw492_32\include/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 \Qt\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37:0, 
       from \Qt\5.5\mingw492_32\include/QtCore/QtCore:4, 
       from \Qt\5.5\mingw492_32\include/QtWidgets/QtWidgetsDepends:3, 
       from \Qt\5.5\mingw492_32\include\QtWidgets/QtWidgets:3, 
       from \mainwindow.cpp:1: 
\Qt\5.5\mingw492_32\include/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, 
      ^
\Qt\5.5\mingw492_32\include/QtCore/qobject.h:254:13: note: template argument deduction/substitution failed: 
\Qt\5.5\mingw492_32\include/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 
\Qt\5.5\mingw492_32\include/QtCore/qobject.h:254:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>' 
In file included from \Qt\5.5\mingw492_32\include/QtCore/qnamespace.h:37:0, 
       from \Qt\5.5\mingw492_32\include/QtCore/qobjectdefs.h:41, 
       from \Qt\5.5\mingw492_32\include/QtCore/qobject.h:40, 
       from \Qt\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37, 
       from \Qt\5.5\mingw492_32\include/QtCore/QtCore:4, 
       from \Qt\5.5\mingw492_32\include/QtWidgets/QtWidgetsDepends:3, 
       from \Qt\5.5\mingw492_32\include\QtWidgets/QtWidgets:3, 
       from \mainwindow.cpp:1: 
\Qt\5.5\mingw492_32\include/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 \Qt\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37:0, 
       from \Qt\5.5\mingw492_32\include/QtCore/QtCore:4, 
       from \Qt\5.5\mingw492_32\include/QtWidgets/QtWidgetsDepends:3, 
       from \Qt\5.5\mingw492_32\include\QtWidgets/QtWidgets:3, 
       from \mainwindow.cpp:1: 
\Qt\5.5\mingw492_32\include/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) 
      ^
\Qt\5.5\mingw492_32\include/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 \Qt\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37:0, 
       from \Qt\5.5\mingw492_32\include/QtCore/QtCore:4, 
       from \Qt\5.5\mingw492_32\include/QtWidgets/QtWidgetsDepends:3, 
       from \Qt\5.5\mingw492_32\include\QtWidgets/QtWidgets:3, 
       from \mainwindow.cpp:1: 
\Qt\5.5\mingw492_32\include/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, 
      ^
\Qt\5.5\mingw492_32\include/QtCore/qobject.h:293:13: note: template argument deduction/substitution failed: 
\Qt\5.5\mingw492_32\include/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 

我們只添加了一個布爾值,將其添加到信號以及相應的插槽,現在我們不知道爲什麼這個sudd恩利不再工作了。

+2

您可以發佈[MCVE(http://stackoverflow.com/help/mcve),以便其他人可以複製和幫忙嗎? – ray

+0

感謝您的鏈接。我會爲下一個問題做這件事。 –

回答

5

我已閱讀此頁上: http://doc.qt.io/qt-5/signalsandslots.html

「如果你的編譯器不支持C++ 11個可變參數模板,此語法只有在信號和槽有6個參數或更少的工作。」

在上述語句中,「此語法」是您正在使用的新連接語法。

好像你的信號槽現在有7個參數。 這可能是問題的潛在原因。

只需仔細檢查一下,您可以使用舊信號插槽連接語法(帶有宏SIGNAL和SLOT的語法)。

必要的修改,以使您的.pro文件中工作:

CONFIG += c++11

+0

你是上帝。非常感謝你! –