【问题标题】:Build error with QT QRgb使用 QT QRgb 构建错误
【发布时间】:2014-10-08 14:20:38
【问题描述】:
QImage source;
QImage dest;
for(unsigned y=0; y<height; ++y)
    {
        for(unsigned x=0; x<width; ++x)
        {
            QColor value = source.color(source.pixelIndex(x, y));   // works fine
            const unsigned r = value.red(), g = value.green(), b = value.blue();
            // some processing
            dest.setColor(dest.pixelIndex(x, y), QRgb(r,g,b));   // build error
        }
    }

我在QRgb(r,g,b) 上遇到构建错误

error: functional cast expression list treated as compound expression

我分离了该行的其他部分,因此只有 QRgb 无法构建(我将它放在单独的行上以隔离问题)

我是 qt 新手,所以我正在查看文档...

https://www.vision.ee.ethz.ch/computing/sepp-irix/qt-2.1.1-to/qcolor.html#24d3b3

https://www.vision.ee.ethz.ch/computing/sepp-irix/qt-2.1.1-to/desktop-desktop-cpp.html#qRgb

据我所知,我的使用方式与他们完全一样……我什至尝试过QRgb(0,0,0),但没有成功。

我无法克服这个构建错误,请帮助

【问题讨论】:

  • 您链接到的文档指向非常古老的 Qt 2.1。你真的在使用这个版本的 Qt 吗?如果没有,为什么不使用最新的文档:qt-project.org/doc/qt-5/index.html
  • 对不起,我应该提一下,我使用的是 Qt 4.7

标签: c++ qt colors rgb build-error


【解决方案1】:

问题是QRgb不是类或函数,而是类型名。我不能将它用作类或函数来构造QRgb 值。您需要改用 qRgb 全局函数,例如:

dest.setColor(dest.pixelIndex(x, y), qRgb(r,g,b));

【讨论】:

  • 我不知道我怎么会错过它!谢谢,我看了这么久!
  • 你必须在你的标题中直接使用#include (因为它确实是一种类型)。
猜你喜欢
  • 1970-01-01
  • 2012-01-10
  • 2015-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多