正如标题所说,我试图将QFileSystemWatcher::directoryChanged(const QString&)
信号连接到lambda,但是当我用g ++(7.2.1)编译它时,我得到以下错误(缩写为SO赢了& #39; t让我发布太多代码):
g++ -c -pipe -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib64/qt5/mkspecs/linux-g++ -o foo.o foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:10:55: error: no matching function for call to ‘QObject::connect(QFileSystemWatcher (&)(), void (QFileSystemWatcher::*)(const QString&, QFileSystemWatcher::QPrivateSignal), main()::<lambda(const QString&)>)’
[] (const QString&) { return 0; });
我用Qt 5.9编译。任何想法为什么会这样? AFAICT我使用的lambda很好。这是我的MWE:
Foo.cpp中:
#include <QObject>
#include <QFileSystemWatcher>
int main()
{
QFileSystemWatcher watcher();
QObject::connect(watcher, &QFileSystemWatcher::directoryChanged,
[] (const QString&) { return 0; });
}
foo.pro:
######################################################################
# Automatically generated by qmake (3.1) Thu Dec 28 11:11:15 2017
######################################################################
TEMPLATE = app
TARGET = foo
INCLUDEPATH += .
CONFIG += c++14
DEFINES += QT_DEPRECATED_WARNINGS
# Input
SOURCES += foo.cpp
答案 0 :(得分:0)
检查第一个参数的类型Qt 5.9 API声明它必须是指向QObject派生对象的指针。
connect(const QObject * sender,PointerToMemberFunction信号,Functor仿函数)