Using #ifdef with qt .pro

  • Hi All,
    Sorry I realise this will be very easy, but I really can't work out what I'm doing wrong. Basically I'm converting some C++ code over to qt, I'm not that good with qt... In my c++ code I use #ifdef to output message grabbed from a tcp server. I only use these to test and debug. So in cpp file I use #ifdef and add the define to my makefile. In qt I've tried this but can get it to work, basically I've done
    int Client::Process_Server_Message( void )
    int ret = 0;

    /is the server running/
    if( message_string.find("Server Running") == 0 )




    then in my .pro file I added the define

    QT += core gui
    QT += network widgets


    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets


    What do I need to added to my pro file to make the code inside #ifdef "appear". Thanks

  • Lifetime Qt Champion



    Also, as note: the
    qDebug() << "stuff" << "more stuff";
    (include QDebug first)
    Is quite handy as its nothing in release builds and then no need for defines etc.

    That worked for me with mingw. (gcc) if using VS, then maybe not.

  • @mrjj said:


    Thanks that worked :D I'm not using qdebug for this as I have a few different things I test for and don't want a load of information thrown at me at once. But thanks!

  • Lifetime Qt Champion

    I just mentioned QDebug so you know it exists. :)
    Happy coding

Log in to reply