Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. #define won't work in QStringList , gives no error

#define won't work in QStringList , gives no error

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestion
4 Posts 3 Posters 6 Views 1 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    1. Why putting #define in char "string" won't process the "command" to "start a new process" , however, compiler is not giving an error ? In debug mode I have literal BT_DATABASE_TEST in "command", 2. I need to make the primary text (*.txt) file a variable - how ?

    #define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
    const char *command = "bluetoothctl show | tee ../../BT_DATABASE/BluetoothDatabase.txt | tee /tmp/temp";
    //const char *command = "bluetoothctl show | tee BT_DATABASE_TEST | tee /tmp/temp"; won't work
    QP->start("/bin/sh", QStringList() << "-c" << command);

    Mircea NeacsuM D 2 Replies Last reply
    0
    • L Lost User

      1. Why putting #define in char "string" won't process the "command" to "start a new process" , however, compiler is not giving an error ? In debug mode I have literal BT_DATABASE_TEST in "command", 2. I need to make the primary text (*.txt) file a variable - how ?

      #define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
      const char *command = "bluetoothctl show | tee ../../BT_DATABASE/BluetoothDatabase.txt | tee /tmp/temp";
      //const char *command = "bluetoothctl show | tee BT_DATABASE_TEST | tee /tmp/temp"; won't work
      QP->start("/bin/sh", QStringList() << "-c" << command);

      Mircea NeacsuM Offline
      Mircea NeacsuM Offline
      Mircea Neacsu
      wrote on last edited by
      #2

      1. You can concatenate strings. Like this:

      #define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
      const char *command = "bluetoothctl show | tee " BT_DATABASE_TEXT " | tee /tmp/temp";

      2. Maybe something like this:

      std::string var = "blah_blah.txt";
      std::string command = std::string("bluetoothctl show | tee ") + var + std::string("" | tee /tmp/temp");
      QP->start("/bin/sh", QStringList() << "-c" << command.c_str());

      Mircea

      L 1 Reply Last reply
      0
      • L Lost User

        1. Why putting #define in char "string" won't process the "command" to "start a new process" , however, compiler is not giving an error ? In debug mode I have literal BT_DATABASE_TEST in "command", 2. I need to make the primary text (*.txt) file a variable - how ?

        #define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
        const char *command = "bluetoothctl show | tee ../../BT_DATABASE/BluetoothDatabase.txt | tee /tmp/temp";
        //const char *command = "bluetoothctl show | tee BT_DATABASE_TEST | tee /tmp/temp"; won't work
        QP->start("/bin/sh", QStringList() << "-c" << command);

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Member 14968771 wrote:

        1. Why putting #define in char "string"...

        The preprocessor does not see #define directives inside string literals.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • Mircea NeacsuM Mircea Neacsu

          1. You can concatenate strings. Like this:

          #define BT_DATABASE_TEST "../../BT_DATABASE/BluetoothDatabase.txt"
          const char *command = "bluetoothctl show | tee " BT_DATABASE_TEXT " | tee /tmp/temp";

          2. Maybe something like this:

          std::string var = "blah_blah.txt";
          std::string command = std::string("bluetoothctl show | tee ") + var + std::string("" | tee /tmp/temp");
          QP->start("/bin/sh", QStringList() << "-c" << command.c_str());

          Mircea

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Basically I can build a string then "convert it" to char, Neat trick. Thanks

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups