QT 學習錯誤總結

Z-Pilgrim發表於2014-03-19

1、  cannot open *** file 可能是沒有關掉剛剛執行的視窗

2、  ** dose not name a type 可能是沒有包含標頭檔案

3、  視窗一閃而過

4、  QT登入視窗呼叫主視窗一閃而過有關問題

www.MyException.Cn   釋出於:2012-11-1110:07:57   瀏覽:72次

QT登入視窗呼叫主視窗一閃而過問題

原始碼:

 

 //如果登入成功

  {

   index mainForm;
   mainForm.show();
   this->hide();
  }

主視窗一閃而過

 

修改為:

 //如果登入成功

  {
   index mainForm =  new inde();
   mainForm.show();
   this->hide();
  }

程式報錯

 

 修改為:

/如果登入成功

  {
   index *mainForm;
   mainForm = new index();
   mainForm->show();
   this->hide();
  }

成功顯示主視窗。

 

 

總結:

 

   index mainForm;
   mainForm.show();

 

mainForm建立在stack上,生命期是大括號內

 

   index *mainForm;
   mainForm = new index();

 

mainForm 通過new建立在heap上,在程式退出時才會被析構

5、  connect

connect(enterBtn,SIGNAL(QPushButton::clicked()),this,SLOT(newmain()));這句話錯了,應該是connect(enterBtn,SIGNAL(clicked()),this,SLOT(newmain()));