Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using #ifdef with qt .pro
Forum Updated to NodeBB v4.3 + New Features

Using #ifdef with qt .pro

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 6.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tony67
        wrote on last edited by
        #3

        @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!

        mrjjM 1 Reply Last reply
        0
        • T tony67

          @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!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved