* see below.
First of all, you cannot connect a signal to a function, you must connect it to a slot of a class, and an instance of this class must also be provided in QObject::connect .
So, the first thing to do is define a class with a slot:
// file 'Ch'
Note that this class must inherit from QObject and have the Q_OBJECT keyword inside it. You must put this class declaration in a *.h file (you cannot have Q_OBJECT in *.cpp files because Qt will not see it).
Now that you have a class with a slot, you can use QObject::connect , the correct way:
QObject::connect(button, SIGNAL(clicked()), &c, SLOT(insert()));
Please note that you must use SIGNAL() macros for signals and SLOT() macros for slots when connecting them.
So, the code in main.cpp should be as follows:
#include "Ch" int main(int argc,char *argv[]) { QApplication app(argc,argv); QPushButton *button=new QPushButton("button"); button->setGeometry(50,100,150,80); C c; QObject::connect(button, SIGNAL(clicked()), &c, SLOT(insert())); button->show(); return app.exec(); }
You see how I provide an instance of the receiver object ( &c ) of the connect() function, you must do this even if your function is static .
And finally, you must app.exec(); because otherwise your program will not have a message loop.
EDIT:
I skipped that the question was about Qt 5. For Qt 5.0, the answer is incorrect.