Congratulations to our 2022 Qt Champions!

Enable GUI for one platform, disable it for others

  • Hello,
    I am beginning a project that needs to run on both Windows and Unix machines. This project will parse a xml file as input and carry out a few simple tasks that will inquire access to sockets, environmental variables etc.

    The problem is that I need to use GUI for the Windows machines and not use it on the Unix machines (since they don't have a graphical interface at all).

    My goal is to make a single project that would be statically compiled for each platform rather than creating 2 separate projects.

    I was wondering if Qt is the right framework for me. Is it possible to not use the GUI and replace it with printouts to STDOUT using #ifndef WIN32 or something of that nature?

    Thank you.

  • See "QtGlobal":

    int main(int argc, char* argv[])
    #ifdef Q_OS_WIN32
    QApplication application(argc, argv);

    // ... (GUI related stuff)

    QCoreApplication application(argc, argv);

    // ... (CLI related stuff)


    return application.exec();


  • Yes, it is possible to use blocks of code only when the requirements are valuable like you want.

    If you use Qt Creator those "not needed" blocks of code will have a grey background helping you to see which code is not active in your project.

  • Excellent.
    Now all I need to know is which IDE to choose.
    My default choice is to use Visual Studio 2008 with the Qt plugin.
    However, I don't know if I would be able to compile the code for use on Unix system.

    Does the Qt plugin bring it's own compiler or uses the one of VS?

    Which IDE do you recommend for this project?

    Thank you.

  • Qt Creator of course ;-)

    Edit: you can choose your compiler : nmake, cmake, mingw-make, ...

  • You have to compile for each platform seperately.

    I suggest using QtCReator as it uses Qt projects files to buikld and is available for those platforms. But with MSVS you can't cross compile for Unix from windows. MSVS plugin just adds siome features not a compiler to MSVS.

    If you create your project with Creator, you have a purs Qt project based on qmake, which can also be used on Unix with installed Qt.

    The you can choose to use mingw or msvs for windows and gcc on linux for example.

  • [quote author="lord$now" date="1310807244"]
    Does the Qt plugin bring it's own compiler or uses the one of VS?

    Which IDE do you recommend for this project?

    Yeah, VS using its own compiler whether or not you using Qt plugin.

    If you are looking for an crossplatform IDE, you can choose QtCreator or eclipse.

    However, you can use Visual Studio under windows, and use another IDE under other platform.

Log in to reply