May 7, 2011 at 5:07pm May 7, 2011 at 5:07pm UTC
Hi,How can i do this?
Example:
This is real code in qt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <qt/QPushButton.h>
#include <qt/QApplication.h>
#include <qt/QFont.h>
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QPushButton cikis("Quit" );
cikis.resize(150,50);
cikis.setFont(QFont("Times" ,16,QFont::Bold));
QObject::connect(&cikis,SIGNAL(clicked()),&app,SLOT(quit()));
cikis.show();
return app.exec();
}
But i want to this method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <qt/QPushButton.h>
#include <qt/QApplication.h>
#include <qt/QFont.h>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QPushButton cikis("Quit" );
cikis.resize(150,50);
cikis.setFont(QFont("Times" ,16,QFont::Bold));
QObject::connect(&cikis,SIGNAL(clicked()),&app,SLOT(exit(1)));
cikis.show();
return app.exec();
}
Why is not run this?Is this cause run with moc?
Last edited on May 7, 2011 at 5:11pm May 7, 2011 at 5:11pm UTC
May 9, 2011 at 10:00am May 9, 2011 at 10:00am UTC
You can only use methods declared as Slots for QObject::connect SLOT.
quit method is declared as a slot method in QApplication class and exit is not a slot.
If you want, you can inherit a class from QApplication and declare your own slot method and call exit( 1 ) in your slot method.
Hope it helps.
May 18, 2011 at 7:07pm May 18, 2011 at 7:07pm UTC
I tried ur said method in QApplication,QPushButton,QCoreApplication..But i am researching.Thank u for help.
May 26, 2011 at 4:24pm May 26, 2011 at 4:24pm UTC
I tried this.And taken this error:
36 F:\QT\QT_My_Func.cpp main.moc: No such file or directory.
How can i do this dont use qmake?
Last edited on May 26, 2011 at 5:11pm May 26, 2011 at 5:11pm UTC
May 30, 2011 at 1:46pm May 30, 2011 at 1:46pm UTC
IIRC, you can't specify using namespace std;
in Qt applications. There are constructs in the std library which is incompatible with the Mock Compiler (moc).
Try instead of omitting using namespace std
and just using the scope resolution operator (::) for explicitly calling std function.
For example, instead of doing:
cout << "Hello World" << endl;
You would use:
std::cout << "Hello World" << std::endl;
May 31, 2011 at 6:19pm May 31, 2011 at 6:19pm UTC
This method did not to avail.