New signall slot syntax
-
Hi I just try to use new yntax and for testing that i wrote this simple code :
@
#include "mainwindow.h"
#include <QApplication>
#include<QLabel>
#include<QTimer>int main(int argc, char argv[])
{
QApplication a(argc, argv);
QLabel lbl=new QLabel;
lbl->setNum(0);
QTimer *timer=new QTimer;
timer->setInterval(1000);
int x=0;
QObject::connect(timer,&QTimer::timeout,&{lbl->setNum(x++);});
//QObject::connect(timer,&QTimer::timeout,lbl,&QLabel::setNum(int));
timer->start();
lbl->show();
return a.exec();
}
@
but when i build the code i get the following error
@
/home/mohsen/qt_projects/qt_android/main.cpp:15: error: expected expression
QObject::connect(timer,&QTimer::timeout,&{lbl->setNum(x++);});@
any suggestions? -
The syntax looks correct, one thing that can cause the error is that you didn't enabled the C++11 for your C++ compiler (the android ndk seems to use gcc 4.8), so you need to add this line into your .pro file: @QMAKE_CXXFLAGS += -std=c++11@
And if you build the same project with a visual c++ that doesn't need (or know) that flag, you can use this:
@gcc : QMAKE_CXXFLAGS += -std=c++11@
to add the flag only for gcc. -
thanks it solved