#define won't work in QStringList , gives no error
-
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); -
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);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
-
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);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. 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