简体   繁体   English

如何从Windows中的命令行运行Qt

[英]How to run Qt from command line in windows

I installed Qt4 and Qt Creator. 我安装了Qt4和Qt Creator。 Now I need to know how can I run an application with in command line. 现在,我需要知道如何在命令行中运行应用程序。

I installed Qt and Qt Creator. 我安装了Qt和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. 如果需要创建项目,则需要打开Qt Creator并创建新项目并在其中编写代码,然后使用Qt Creator进行编译/构建。 Is that the procedure in Qt. 是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). 我想深入了解如何手动创建.pro文件(而不是Qt Creator)。 And how to compile it outside the Qt Creator. 以及如何在Qt Creator之外进行编译。

(SIMPLY I DON'T WANT TO USE QT-CREATOR, BUT I NEED TO WRITE QT PROGRAMS... :D) (很简单,我不想使用QT创建器,但是我需要编写QT程序...:D)

Take a look at the qmake manual to write your .pro files manually ( direct link to project files section ). 看一下qmake手册,手动编写.pro文件( 直接链接到项目文件部分 )。

Then on a command prompt just run: 然后在命令提示符下运行:

qmake MyProFile.pro
make

(or nmake if you use the Microsoft compiler) (如果使用Microsoft编译器,则为nmake)

You can even generate a basic pro file with qmake . 您甚至可以使用qmake生成基本的pro文件。 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: 如果您是说如何编写非GUI Qt应用程序,那么我会这样做:

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. 这至少允许您编写一个使用Qt数据结构以及信号和插槽的CLI应用程序,但是由于在应用程序代码运行时尚未执行a.exec(),因此您可能无法使用需要事件队列的QTimers之类的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM