How do I create a simple Qt console application in C++?

前端 未结 7 1070
别那么骄傲
别那么骄傲 2020-11-28 22:06

I was trying to create a simple console application to try out Qt\'s XML parser. I started a project in VS2008 and got this template:

int main(int argc, char         


        
7条回答
  •  感情败类
    2020-11-28 22:33

    You could fire an event into the quit() slot of your application even without connect(). This way, the event-loop does at least one turn and should process the events within your main()-logic:

    #include 
    #include 
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app( argc, argv );
    
        // do your thing, once
    
        QTimer::singleShot( 0, &app, &QCoreApplication::quit );
        return app.exec();
    }
    

    Don't forget to place CONFIG += console in your .pro-file, or set consoleApplication: true in your .qbs Project.CppApplication.

提交回复
热议问题