当前位置: 技术问答>linux和unix
Qt入门级错误
来源: 互联网 发布时间:2016-10-24
本文导语: 我写了个Qt小程序: 各 geometry.h: #include class QLabel; class Geometry:public QDialog { Q_OBJECT public: Geometry(); QLabel *x; QLabel *y; }; geometry.cpp: void Geometry::updateLabel() { QString t; x->setText(t.setNum(x())); y->setText(t.setNum(y())); } 运...
我写了个Qt小程序:
各
geometry.h:
#include
class QLabel;
class Geometry:public QDialog
{
Q_OBJECT
public:
Geometry();
QLabel *x;
QLabel *y;
};
geometry.cpp:
void Geometry::updateLabel()
{
QString t;
x->setText(t.setNum(x()));
y->setText(t.setNum(y()));
}
运行时,
x->setText(t.setNum(x()));
y->setText(t.setNum(y()));
这两句提示x() cannot be used as a function。
换成QDialog::x()就可以了
但是我在geometry.h中不是继承了QDialog了吗?(class Geometry:public QDialog),
另外书上也是直接用的,没加QDialog。为什么?
各
geometry.h:
#include
class QLabel;
class Geometry:public QDialog
{
Q_OBJECT
public:
Geometry();
QLabel *x;
QLabel *y;
};
geometry.cpp:
void Geometry::updateLabel()
{
QString t;
x->setText(t.setNum(x()));
y->setText(t.setNum(y()));
}
运行时,
x->setText(t.setNum(x()));
y->setText(t.setNum(y()));
这两句提示x() cannot be used as a function。
换成QDialog::x()就可以了
但是我在geometry.h中不是继承了QDialog了吗?(class Geometry:public QDialog),
另外书上也是直接用的,没加QDialog。为什么?
|
x不要new一下么?我也记不清了
|
QLabel *x;
QLabel *y;
可能是名重了的原因吧
QLabel *y;
可能是名重了的原因吧
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。