Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 无法从常量QChar转换为int_Qt - Fatal编程技术网

Qt 无法从常量QChar转换为int

Qt 无法从常量QChar转换为int,qt,Qt,我对这个代码有问题 #define twobit(ch) ((toupper(ch)) == 'S' ? 0LL : \ (toupper(ch)) == 'M' ? 1LL : \ (toupper(ch)) == 'F' ? 2LL : 3LL) const QString pop("SWDGMKF"); qDebug()<<twobit(pop[2

我对这个代码有问题

 #define twobit(ch) ((toupper(ch)) == 'S' ? 0LL : \
                             (toupper(ch)) == 'M' ? 1LL : \
                             (toupper(ch)) == 'F' ? 2LL : 3LL)

 const QString pop("SWDGMKF");

    qDebug()<<twobit(pop[2]); //Erorr
#定义两位(ch)((toupper(ch))='S'?0LL:\
(toupper(ch))='M'?1LL:\
(toupper(ch))='F'?2LL:3LL)
常量QString pop(“SWDGMKF”);

qDebug()QChar表示unicode字符。因此,无法安全地将其转换为字符。如果您知道它只包含ASCII或拉丁文字符,则可以分别使用toAscii()或toLatin1()进行转换

如果可能的话,我会避免转换成char,而是使用QChar方法。也就是说,不要使用toupper()而是使用:

ch.toUpper() == QLatin1Char('S') ? 0LL : \
  ...