|
5Qter豆
大家好,小弟初学QT,编了个小程序,读取注册表的信息,然后 按条显示出来,显示的时候后面显示一个按钮,然后再点一下按钮的话,可以改变显示的内容!
程序如下,分为gettime.h gettime.cpp main.cpp
遇到的问题是,程序运行的结果如果如图所示,每次运行完后,只有最后的一个按钮有效果,其他的点不到,过一会儿以后,部分其他的按钮也可以点! 请教各位大神,改如何修改,才能解决的,使得每一个按钮都能及时反应!
先谢过帮忙的各位了!
#ifndef GETTIME_H
#define GETTIME_H
#include<QDialog>
#include<QLabel>
#include<QPushButton>
#include<QString>
class getTime:public QDialog
{
Q_OBJECT
public:
getTime(QWidget *parent = 0);
~getTime();
QLabel *label;
QPushButton *btn;
private:
public slots:
void currentTime();
signals:
void getData(QString);
};
#endif // GETTIME_H
///////////////////////////////////////////////////////////////////////////////////
#include"getTime.h"
#include<QTime>
getTime::getTime(QWidget *parent)
Dialog(parent)
{
label = new QLabel("Item", this);
btn = new QPushButton("On/Off", this);
label->move(10,40);
btn->move(200,35);
connect(btn, SIGNAL(clicked()), this, SLOT(currentTime()));
connect(this, SIGNAL(getData(QString)), label, SLOT(setText(QString)));
}
getTime::~getTime()
{
delete label;
delete btn;
}
void getTime::currentTime()
{
emit getData("Hello");
}
///////////////////////////////////////////////////////////////////////////////////main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\Windows\\CurrentVersion\\Run");
QStringList keyList = reg.childKeys();
QWidget *w = new QWidget(0);
w->setWindowTitle(QObject::tr("windows开机启动项"));
w->resize(300,400);
int i = 0;
foreach(QString key, keyList) { i++;}
getTime *G = new getTime[i+1];
i = 0;
keyList = reg.childKeys();
foreach(QString key, keyList)
{
G[i].setParent(w);
G[i].label->setText(key);
G[i].move(10,i*40);
i++;
}
w->show();
int ret = a.exec();
delete[] G;
return ret;
}
|
|