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
    .cpp
    [code]
    int Client::Process_Server_Message( void )
    {
    int ret = 0;

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

    #ifdef DEBUG_SERVER_MESSAGE

     std::cout<<message_string<<std::endl;
    

    #endif
    [/code]

    then in my .pro file I added the define
    [code]

    QT += core gui
    QT += network widgets

    DEFINES += DEBUG_SERVER_MESSAGE

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    ......
    [/code]

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


  • Qt Champions 2016

    Hi

    try
    DEFINES += "DEBUG_SERVER_MESSAGE=1"

    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.

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



  • @mrjj said:

    DEFINES += "DEBUG_SERVER_MESSAGE=1"

    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!


  • Qt Champions 2016

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.