QT中的Qwidget类的构造及显示区别
示例代码:
1、头文件
class MainWindow : public QMainWindow
{
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
2、实现文件
代码1
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QLabel label=new QLabel(this);
label.setGeometry(10,10,100,20);
QDateTime *datetime=new QDateTime(QDateTime::currentDateTime());
label.setText(datetime->date().toString());
}
这个是可以正常显示的,在mainwindow中有个label标签显示时间。
但是我将上述实现代码改为:
代码2
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QLabel label;
label.setParent(this);
label->setGeometry(10,10,100,20);
QDateTime *datetime=new QDateTime(QDateTime::currentDateTime());
label->setText(datetime->date().toString());
}
之后就不能显示label标签,这是为什么?
我在mainwindow的声明中添加一个label成员,对这个成员使用代码2同样可以显示,这又是为什么?
1、头文件
class MainWindow : public QMainWindow
{
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
2、实现文件
代码1
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QLabel label=new QLabel(this);
label.setGeometry(10,10,100,20);
QDateTime *datetime=new QDateTime(QDateTime::currentDateTime());
label.setText(datetime->date().toString());
}
这个是可以正常显示的,在mainwindow中有个label标签显示时间。
但是我将上述实现代码改为:
代码2
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QLabel label;
label.setParent(this);
label->setGeometry(10,10,100,20);
QDateTime *datetime=new QDateTime(QDateTime::currentDateTime());
label->setText(datetime->date().toString());
}
之后就不能显示label标签,这是为什么?
我在mainwindow的声明中添加一个label成员,对这个成员使用代码2同样可以显示,这又是为什么?
...全文
相关推荐
QWidget,QMainWindow和QDialog的区别
QWidget,QMainWindow和QDialog的区别.
Qt利用帧动画实现所有动画效果(QWidget)
对应博文地址:http://blog.csdn.net/CSND_Ayo/article/details/70175385
qt实现的16进制显示界面
qt实现的16进制显示控件,可以用来显示串口原始数据,同时支持字符串显示。资源为一个调用demo。用作参考。
QT实现动态波形的实时显示
QT上实现动态波形的显示,使用定时器来模拟数据的变化,在qt界面上实时显示当前的数值变化,可以通过波形更加清晰直观的了解数据的变化趋势。
两个QWidget互相交换显示
两个QWidget互相交换显示


Windows SDK/API
