找回密码
 立即注册
收起左侧

同一个类实例化的部件(label,button),部分button没有反应

0
回复
7247
查看
[复制链接]

尚未签到

来源: 2016-7-26 15:07:30 显示全部楼层 |阅读模式
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;
}


附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了