我遇到了以下问题: 这就是工作:
#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/