tags:

views:

349

answers:

2

hi all, i installed Qt4 and Qt creator. now i need to know how can i run an application with in command line.

I installed QT and QT creator. If i need to create a project i need to open the Qt Creator and create new project and write the code there, compile/build with the QT creator. Is that the procedure in QT. So in this case am not aware of how build and executions happening.

I would like know in depth, how to create a .pro file manually(not with QT Creator). and how to compile it out side the QT creator. (SIMPLY I DON'T WANT TO USE QT-CREATOR, BUT I NEED TO WRITE QT PROGRAMS... :D)

A: 

If you mean how to write a non-GUI Qt application, I do it like this:

int main(int argc, char *argv[])
{
        QCoreApplication a(argc, argv); 

        //Put your application code here

        //This line shouldn't be reached until the application is quitting
        QTimer::singleShot(0, &a, SLOT(quit()));
        return a.exec();
}

This at least allows you to write a CLI application that uses Qt data structures and signals and slots, but since a.exec() hasn't been executed yet at the time your application code is running, you probably won't be able to use things like QTimers that require the event queue.

Colin
+2  A: 

Take a look at the qmake manual to write your .pro files manually (direct link to project files section).

Then on a command prompt just run:

qmake MyProFile.pro
make

(or nmake if you use the Microsoft compiler)

You can even generate a basic pro file with qmake. If your project is simple and do not use external libs, you'll be able to use it as is. For that in your project folder, just run:

qmake -project -o MyProject.pro
gregseth