• 8001阅读
  • 4回复

[已解決]修改label->setText問題 [复制链接]

上一主题 下一主题
离线flykof
 
只看楼主 倒序阅读 楼主  发表于: 2009-04-21
下面程式中紅色選起來的部分,是我要問的問題。
我所要作的設定是,當值有改變時,就會將label的text變更為ddt,但編譯後執行時出現的問題是,label的text並沒有任何改變,
還是一樣為初始設定的1234,但printf("123"); 這行指令確實是有執行。
煩請高手指導我,是否哪個地方有錯誤?

---mainwindows.h---
class QDialogButtonBox;
class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
class QLabel;
class Makerfid;

class MainWindows : public QWidget
{
      Q_OBJECT
      
public:
      MainWindows(QWidget *parent = 0);
      void SetPushButton();
public slots:
      void Set();
private:
      QPushButton *LoadPushButton;
      QLabel *IDCardLabel;
      QLabel *IDCardNumberLabel;
      QHBoxLayout *HorizeontallyLayout;
      QVBoxLayout *VerticalLayout1;
      QVBoxLayout *VerticalLayout2;
      QDialogButtonBox *buttonBox;
      Makerfid *rfid;
      
};

-----mainwindows.cpp-------
MainWindows :: MainWindows(QWidget *parent)
     : QWidget(parent)
{
     rfid=new Makerfid();
    
     /* 設定每秒鐘讀取TAG */
     printf("set AUTO Read Tag in one second\n");
     QTimer *timer = new QTimer(rfid);
     QObject::connect(timer, SIGNAL(timeout()), rfid, SLOT(ReadTagInfo()));
     timer->start(1000);  
    
     connect(rfid,SIGNAL(cardidChanged(int)),this,SLOT(Set()));
    
     /* 設定Label */
     IDCardLabel = new QLabel(tr("Student ID_Card : "));
     IDCardNumberLabel = new QLabel(tr("Default!"));
     IDCardNumberLabel->setText("1234");

     /* 設定按鈕 */
     printf("set pushbutton\n");
     LoadPushButton = new QPushButton(tr("Load"));
    
     printf("set buttonbox\n");
     buttonBox = new QDialogButtonBox;
     buttonBox->addButton(LoadPushButton, QDialogButtonBox::ActionRole);
    
    
     /* connect設定可用按鈕讀取TAG */
     printf("set connect!\n");
     connect(LoadPushButton, SIGNAL(clicked()), qApp, SLOT(quit()));
    
     /* 設定版面佈置 */
     printf("set verticallayout!\n");
     VerticalLayout1 = new QVBoxLayout;
     VerticalLayout1->addWidget(IDCardLabel);
     VerticalLayout1->addWidget(IDCardNumberLabel);
    
     VerticalLayout2 = new QVBoxLayout;
     VerticalLayout2->addLayout(VerticalLayout1);
     VerticalLayout2->addWidget(LoadPushButton);
     setLayout(VerticalLayout2);    
    
     setWindowTitle(tr("Show Tag Info!"));      
}

void MainWindows::Set()
{
     printf("123");
     LoadPushButton->setText("ddt");
}
[ 此帖被flykof在2009-04-24 10:08重新编辑 ]
离线xnmd2000
只看该作者 1楼 发表于: 2009-04-23
  LoadPushButton->setText("ddt");

这个也不是你的LABEL啊。 你的LoadPushButton 这个按钮变了没?
离线318065268
只看该作者 2楼 发表于: 2009-04-23
connect(rfid,SIGNAL(cardidChanged(int)),this,SLOT(Set()));
这样显然不行,SIGNAL的参数和SLOT的参数要类型、数量、顺序一致。
这样的错误不会在编译时被检查出来,但是运行的时候会有提示,你可以注意看看。
Email  rsail@126.com(私人邮箱)
QQ:   318065268
离线318065268
只看该作者 3楼 发表于: 2009-04-23
可以用connect(rfid,SIGNAL(cardidChanged(QString)),LoadPushButton,SLOT(setText(QString)));
发射信号的时候
emit  cardidChanged(QString :: number(num));
Email  rsail@126.com(私人邮箱)
QQ:   318065268
离线flykof
只看该作者 4楼 发表于: 2009-04-24
感謝各位大大的回覆,後來發現果然是 LoadPushButton->setText("ddt"); 設錯,囧rz...
LoadPushButton 這個按鈕有變,只是注意的地方不再這,所以才一直沒發現。

感謝2F、3F大大給的建議,感激不盡。
快速回复
限100 字节
 
上一个 下一个