开发者

How to run Qt from command line in windows

开发者 https://www.devze.com 2022-12-22 12:43 出处:网络
I installed Qt4 and Qt Creator. Now I need to know how can I run an application with in command line.开发者_Go百科

I installed Qt4 and Qt Creator. Now I need to know how can I run an application with in command line.开发者_Go百科

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 I 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 outside the Qt Creator.

(SIMPLY I DON'T WANT TO USE QT-CREATOR, BUT I NEED TO WRITE QT PROGRAMS... :D)


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消