I have discovered something with a ternary statement that I don't quite understand.
If I use a normal if - else construct I have no problem in compiling, however using the same variables in a ternary statement I get a Invalid conversion from int to constant char* error.

Here is my code:

Header file

Qt Code:
  1. #ifndef TERNARYTEST_H
  2. #define TERNARYTEST_H
  3. #include <QString>
  4. #include <QDebug>
  5. #include <QRegExp>
  6.  
  7. typedef QMap<QString, QVariant> MyMap;
  8.  
  9. void setup(void);
  10. bool isInt(QString);
  11.  
  12. #endif // TERNARYTEST_H
To copy to clipboard, switch view to plain text mode 

and the main file

Qt Code:
  1. #include <QCoreApplication>
  2. #include <ternaryTest.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QCoreApplication a(argc, argv);
  7. setup();
  8. return a.exec();
  9. }
  10.  
  11. void setup()
  12. {
  13. MyMap map;
  14.  
  15. QString str = "Release Time: 2000";
  16. QString val;
  17. QString key;
  18. bool ok;
  19. val = (str.section(':',1,-1)).trimmed();
  20. key = (str.section(':',0,0)).toUpper().trimmed();
  21. qDebug()<<val;
  22. qDebug()<<key;
  23.  
  24. if ( isInt(val) )
  25. map[key] = val.toInt();
  26. else
  27. map[key] = val;
  28.  
  29. qDebug()<<map;
  30.  
  31. map[key] = isInt(val) ? val.toInt(&ok, 10) : val; /// Error compiling here
  32.  
  33.  
  34. exit(0);
  35. }
  36.  
  37. bool isInt(QString s)
  38. {
  39. QRegExp re("\\d*");
  40. return re.exactMatch(s);
  41. }
To copy to clipboard, switch view to plain text mode 

As the if - else constructs works fine I have no problem. Just curious as to the compiler error on the ternary statement.

The object of the program is to use everything before the first occurrence of a colon as a key in a QMap and everything after, including any colons as a QVariant value (Int or QString).

Thanks in advance.
Regards
Graham Benney