c++ - QT - 指向 QColor 的指针可以直接访问,但不能

标签 c++ qt

我遇到了以下问题: 这就是工作:

#include <QtCore/QCoreApplication>
#include <QColor>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QColor *c = new QColor();
    c->setRgb(12,123,13);
    return a.exec();
}

但这不是:

#include <QtCore/QCoreApplication>
#include <QColor>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QColor c();
    c.setRgb(123,213,2);
    return a.exec();
}

Qtcreator 告诉我:

request for member 'setRgb' in 'c' which is of non-class type 'Qcolor()'

这是怎么回事?

编辑 好的解决方案是使用不带“()”的 Qcolor c,但如果它是类成员怎么办?然后直接访问仍然不行...即:

class X{

QColor c;

  void func(){
     c.setRgb(1,2,3);
  }
}

最佳答案

这个

QColor c();

是一个函数声明。将其更改为

QColor c;

这可能是数百个类似问题的重复......

关于c++ - QT - 指向 QColor 的指针可以直接访问,但不能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4359452/

相关文章:

c++ - QBoxLayout 与 QMainWindow 对比 QWidget

c++ - 如何在不使用委托(delegate)的情况下在 QML 中显示模型数据

c++ - 我的线程仍然卡住我的 GUI

c++ - 创建特定窗口后如何调整其大小?

c++ - C++ 中复杂的 Typedef

c++ - Direct3D C++ 纹理映射

android - 在 Qt 中构建 Android 项目不再有效

C++17 类模板参数推导在初始化列表中不起作用,为什么?

c++ - 双抛物面阴影贴图

c++ - QToolButton 在 QFrame/QWidget 中的视觉行为