• 5806阅读
  • 4回复

qt4界面按钮没反应的问题。。。急~~~ [复制链接]

上一主题 下一主题
离线mkyang0627
 
只看楼主 正序阅读 楼主  发表于: 2009-04-07
我用tabwidget做了2个登陆界面,一个是admin,一个是user,admin登录成功后可以进入第三个页面管理货物,user登录成功后可以进入第四个页面购买货物。。。
这些功能都可以实现,登录成功后都可以弹出新的窗口,但是新的窗口上的按钮点的都没反应,我已经给他们连接了信号和槽,点了按钮后跳出新的窗体,但是都没用,
也就是说只有tabwidget里面的2个登录界面的按钮是有用的。。。新窗体的按钮都没用,这是为什么。。。

#include "mywidget.h"

#include <QtGui/QMessageBox>
#include <QtCore/QString>
#include <QtGui/QIcon>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    
    
    setWindowTitle(tr("Welcome to Shopping System"));
    QTabWidget *tabWidget = new QTabWidget(this);    
    
    QDialog *w2 = new QDialog;
    secondUi.setupUi(w2);
    
    QDialog *w3 = new QDialog;
    thirdUi.setupUi(w3);
  

    tabWidget->addTab(w2,"admin login");
    tabWidget->addTab(w3,"user login");
  

    tabWidget->resize(400,350);

    connect(secondUi.pushButton1,SIGNAL(clicked()),this,SLOT(adlogin()));        //admin登录成功后进入货物管理界面
    connect(secondUi.pushButton2,SIGNAL(clicked()),this,SLOT(close()));    
    connect(thirdUi.pushButton1,SIGNAL(clicked()),this,SLOT(usrlogin()));            //user登录成功后进入购买界面
    connect(thirdUi.pushButton2,SIGNAL(clicked()),this,SLOT(close()));  
//second和third是两个登陆界面,嵌在tabwidget中,按钮功能正常实现,输入密码可以进入新界面
    connect(fifthUi.pushButton1,SIGNAL(clicked()),this,SLOT(buy()));                      //点击购买按钮进入信息登记界面
    connect(fifthUi.pushButton11,SIGNAL(clicked()),this,SLOT(intro()));                  //弹出新窗口介绍本店
//第五个界面是购买界面,但是这个界面上的按钮都没反应。。。

}





void MyWidget::adlogin()
{
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("d:\\mkyang\\ymk.db");
    if(db.open())
    {QSqlQuery query;
     query.exec("Create table if not exists adlogin(adname VARCHAR(20),"
                     "password VARCHAR(20))");
     query.exec("insert into adlogin values('admin','admin')");                  
     QString s1,s2;
     query.exec("select * from adlogin");
         while(query.next())
         {        s1=query.value(0).toString();
                        
                         s2=query.value(1).toString();
          }
         if(secondUi.lineEdit1->text()==s1&&secondUi.lineEdit2->text()==s2)
      { QMessageBox::about(this,tr("Welcome!"),tr("administrator login successfully!"));
         QDialog *w4 = new QDialog;
         fourthUi.setupUi(w4);
         w4->show();
         this->hide();
     }
          else
          {
             secondUi.lineEdit1->setText("");
             secondUi.lineEdit2->setText("");
             QMessageBox::about(this,tr("Error!"),tr("Wrong name or password!"));
           }
    }

else
     QMessageBox::about(this,tr("Error!"),tr("database not open!"));
    
    
}

void MyWidget::usrlogin()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("d:\\mkyang\\ymk.db");
    if(db.open())
    {QSqlQuery query;
     query.exec("Create table if not exists usrlogin(usrname VARCHAR(20),"
                     "password VARCHAR(20))");
     query.exec("insert into usrlogin values('user','user')");                  
     QString s1,s2;
     query.exec("select * from usrlogin");
         while(query.next())
         {
                          s1=query.value(0).toString();
                        
                         s2=query.value(1).toString();
          }
                         if(thirdUi.lineEdit1->text()==s1&&thirdUi.lineEdit2->text()==s2)
     { QMessageBox::about(this,tr("Welcome!"),tr("Wish you pleasant shopping!"));
       QDialog *w5 = new QDialog;
                         fifthUi.setupUi(w5);  
                         w5->show();
        this->hide();     }

     else
     {
         thirdUi.lineEdit1->setText("");
                           thirdUi.lineEdit2->setText("");
         QMessageBox::about(this,tr("Error!"),tr("Wrong name or password!"));
                       }
    }

else
     QMessageBox::about(this,tr("Error!"),tr("database not open!"));
    
    
    
}

void MyWidget::intro()
{
   QDialog *w6 = new QDialog;
   sixthUi.setupUi(w6);  
   w6->show();
}

void MyWidget::buy()
{
   QDialog *w7 = new QDialog;
   seventhUi.setupUi(w7);  
   w7->show();
   this->hide();
}

在tabwidget的两个登录界面,功能都可以实现,但是进入新的页面后按钮功能却无法实现,这是为什么。。。
附件: mkyang.rar (1404 K) 下载次数:11
离线318065268
只看该作者 4楼 发表于: 2009-04-09
QDialog *w6 = new QDialog;
   sixthUi.setupUi(w6);  
//   w6->show();
sixthUi->show();
这样试试吧。要show()的似乎不应该是w6,而是外围的那个。虽然不太清楚,但感觉像加滚动条的流程,道理应该是一样的。
Email  rsail@126.com(私人邮箱)
QQ:   318065268
离线duduqq

只看该作者 3楼 发表于: 2009-04-08
把这句去掉试试会不会弹出个对话框sixthUi.setupUi(w6);  
你好像是把对话框加到其他的窗体上了,有可能就是这样显示不出来。
离线tinglan

只看该作者 2楼 发表于: 2009-04-08
系统不一样,环境配置就更不同,没法帮你找原因了!
离线mkyang0627
只看该作者 1楼 发表于: 2009-04-07
谁知道是为什么。。。
快速回复
限100 字节
 
上一个 下一个