Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.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 QString字符串/文本格式_Qt_Formatting_Qstring - Fatal编程技术网

Qt QString字符串/文本格式

Qt QString字符串/文本格式,qt,formatting,qstring,Qt,Formatting,Qstring,我尝试使用arg()函数格式化QString,如下所示: QColor color = QColorDialog::getColor(Qt::blue, this); .... QString tStr = QString("R: %1 G: %2 B: %3").arg( color.red(), color.green(), color.blue()); 这里我得到一个“整数除零异常” 背景:在VS2010中使用Qt插件。对Qt框架来说是全新的 有什么建议吗 谢谢您应该将该行更改为 Q

我尝试使用arg()函数格式化QString,如下所示:

QColor color = QColorDialog::getColor(Qt::blue, this);

....

QString tStr = QString("R: %1 G: %2 B: %3").arg( color.red(), color.green(), color.blue());
这里我得到一个“整数除零异常”

背景:在VS2010中使用Qt插件。对Qt框架来说是全新的

有什么建议吗


谢谢

您应该将该行更改为

QString tStr = QString("R: %1 G: %2 B: %3")
    .arg(color.red()).arg(color.green()).arg(color.blue());
我只能假设您的代码映射到这个重载的
arg()


我很惊讶这会导致一个被零除的错误,因为没有人在没有先检查0或捕获异常的情况下执行除法:)无论如何,我在Qt 4.7.4/Windows 7/MinGW上对您的代码进行了测试,没有错误,只是结果字符串错误。

检查了您的代码,结果正常。很明显,对于arg()函数的误解是什么。这个语法来自xprintf()和String.Format()行星,看起来有点奇怪。无论我们如何生活和学习:)。多谢各位。
QString QString::arg(int a, int fieldWidth = 0, int base = 10, 
    const QChar & fillChar = QLatin1Char( ' ' )) const