std-C++ in QT4

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

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.








I tried ur said method in QApplication,QPushButton,QCoreApplication..But i am researching.Thank u for help.
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <QObject>
#include <QPushButton>
#include <QApplication>
#include <QFont>
#include <stdio.h>
using namespace std;


class Exit:public QObject
{
    Q_OBJECT
public:
    Exit(int exitNumber, QObject *parent =0):QObject(parent),m_exitNumber(exitNumber){}
    virtual ~Exit(){}

public slots:
    void exit(){qApp->exit(m_exitNumber);}
private:
    int m_exitNumber;

};


int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
    QPushButton cikis("Quit");
    Exit* failExit = new Exit(1);
    cikis.resize(150,50);
    cikis.setFont(QFont("Times",16,QFont::Bold));
    QObject::connect(&cikis,SIGNAL(clicked()),failExit,SLOT(exit()));
    cikis.show();
    return app.exec();
}

#include "main.moc" 

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
I tried this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <qt/QObject.h>
#include <qt/QPushButton.h>
#include <qt/QApplication.h>
#include <qt/QFont.h>
#include <stdio.h>
using namespace std;


class Exit:public QObject
{
    Q_OBJECT
public:
    Exit(int exitNumber, QObject *parent =0):QObject(parent),m_exitNumber(exitNumber){}
    ~Exit();

public slots:
    void exit(){qApp->exit(m_exitNumber);}
private:
    int m_exitNumber;

};


int main(int argc, char *argv[])
{
    QApplication app(argc,argv);
    QPushButton cikis("Quit");
    Exit* failExit = new Exit(1);
    cikis.resize(150,50);
    cikis.setFont(QFont("Times",16,QFont::Bold));
    QObject::connect(&cikis,SIGNAL(clicked()),failExit,SLOT(exit()));
    cikis.show();
    return app.exec();
}


And i taken this:
1
2
3
  [Linker error] undefined reference to `vtable for Exit' 
  ld returned 1 exit status 
 F:\QT\Makefile.win [Build Error]  [QT_My_Func.exe] Error 1  
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;
This method did not to avail.
Topic archived. No new replies allowed.