开发者

QT - pointer to QColor works direct access don't

I got following issue: That's work:

#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();
}

but this don't:

#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 get me:

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

Wh开发者_C百科at is going on?

EDIT OK solution was use Qcolor c without '()', but what if it is member of class? Then direct access still doesn't work... ie:

class X{

QColor c;

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


This

QColor c();

is a function declaration. Change it to

QColor c;

That's a possible duplicate of hundreds of similar questions....


Declare like

QColor c;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜