• 5976阅读
  • 3回复

关于登陆界面的问题 [复制链接]

上一主题 下一主题
离线buptzhw
 
只看楼主 正序阅读 楼主  发表于: 2010-07-12
小弟问个问题:用Qt designer的页面,主程序界面完成,今天想加一个登录界面

下面写的代码。编译通过,但是不执行。显示:程序停止,分段错误。请问问题在哪里呢?


#include <QtGui>
#include "login.h"
Login::Login(QWidget* parent, Qt::WFlags fl)
: QDialog( parent, fl ), Ui::Dialog()
{
setupUi(this);
}
Login::~Login()
{
}
void Login::login()
{
if(name->text() == tr("zhw") && pwd->text() == tr("123456"))
QDialog::accept();
else
{
QMessageBox::information(NULL,tr("warning"),tr("Error"));
name->clear();
pwd->clear();
name->setFocus();
}
}


#include <QApplication>

#include "mainfrm.h"

#include "login.h"



int main(int argc, char *argv[])

{

      QApplication app(argc, argv);

MainFrm mainfrm;

Login login;

if(login.exec()==QDialog::Accepted)

mainfrm.show();

return app.exec();

}

xtfllbl 留:以后请不要使用巨大字体,严重影响看代码效率


[ 此帖被xtfllbl在2010-07-12 16:54重新编辑 ]
离线buptzhw
只看该作者 3楼 发表于: 2010-07-13
回 2楼(tootzoe) 的帖子
感谢您,您提醒了我
为了方便,我把函数名,对话框名,类名都设成一样的了,呵呵。很低级的错误啊
离线tootzoe
只看该作者 2楼 发表于: 2010-07-12
初学者吧.....你把判断语句写在构造函数中怎么有作用.....

  1. /********************************************************************************
  2. ** Form generated from reading UI file 'login.ui'
  3. **
  4. ** Created: Mon Jul 12 21:36:32 2010
  5. **      by: Qt User Interface Compiler version 4.7.0
  6. **
  7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
  8. ********************************************************************************/
  9. #ifndef UI_LOGIN_H
  10. #define UI_LOGIN_H
  11. #include <QtCore/QVariant>
  12. #include <QtGui/QAction>
  13. #include <QtGui/QApplication>
  14. #include <QtGui/QButtonGroup>
  15. #include <QtGui/QDialog>
  16. #include <QtGui/QDialogButtonBox>
  17. #include <QtGui/QHeaderView>
  18. #include <QtGui/QLabel>
  19. #include <QtGui/QLineEdit>
  20. QT_BEGIN_NAMESPACE
  21. class Ui_Login
  22. {
  23. public:
  24.     QDialogButtonBox *buttonBox;
  25.     QLineEdit *UserName;
  26.     QLineEdit *PWD;
  27.     QLabel *label;
  28.     QLabel *label_2;
  29.     void setupUi(QDialog *Login)
  30.     {
  31.         if (Login->objectName().isEmpty())
  32.             Login->setObjectName(QString::fromUtf8("Login"));
  33.         Login->resize(400, 300);
  34.         buttonBox = new QDialogButtonBox(Login);
  35.         buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
  36.         buttonBox->setGeometry(QRect(30, 240, 341, 32));
  37.         buttonBox->setOrientation(Qt::Horizontal);
  38.         buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  39.         UserName = new QLineEdit(Login);
  40.         UserName->setObjectName(QString::fromUtf8("UserName"));
  41.         UserName->setGeometry(QRect(160, 90, 113, 20));
  42.         PWD = new QLineEdit(Login);
  43.         PWD->setObjectName(QString::fromUtf8("PWD"));
  44.         PWD->setGeometry(QRect(160, 140, 113, 20));
  45.         label = new QLabel(Login);
  46.         label->setObjectName(QString::fromUtf8("label"));
  47.         label->setGeometry(QRect(70, 90, 54, 12));
  48.         label_2 = new QLabel(Login);
  49.         label_2->setObjectName(QString::fromUtf8("label_2"));
  50.         label_2->setGeometry(QRect(70, 150, 54, 12));
  51.         retranslateUi(Login);
  52.         QObject::connect(buttonBox, SIGNAL(accepted()), Login, SLOT(TOOTAccpted())  );
  53.         QObject::connect(buttonBox, SIGNAL(rejected()), Login, SLOT(reject()));
  54.         QMetaObject::connectSlotsByName(Login);
  55.     } // setupUi
  56.     void retranslateUi(QDialog *Login)
  57.     {
  58.         Login->setWindowTitle(QApplication::translate("Login", "Dialog", 0, QApplication::UnicodeUTF8));
  59.         label->setText(QApplication::translate("Login", "\347\224\250\346\210\267\345\220\215", 0, QApplication::UnicodeUTF8));
  60.         label_2->setText(QApplication::translate("Login", "\345\257\206\347\240\201", 0, QApplication::UnicodeUTF8));
  61.     } // retranslateUi
  62. };
  63. namespace Ui {
  64.     class Login: public Ui_Login {};
  65. } // namespace Ui
  66. QT_END_NAMESPACE
  67. #endif // UI_LOGIN_H





  1. /**************************************************************************
  2. **   Copyright @ 2010 TOOTzoe.com
  3. **   Special keywords: Administrator 2010-7-12 2010
  4. **   Environment variables: %$VARIABLE%
  5. **   To protect a percent sign, use '%'.
  6. **
  7. **
  8. **   E-mail : toot@tootzeo.com
  9. **   Tel    : 13712943464
  10. **   Website: http://www.tootzoe.com
  11. **
  12. **************************************************************************/
  13. //------------------------------------------------------------------------
  14. #ifndef LOGIN_H
  15. #define LOGIN_H
  16. #include <QDialog>
  17. namespace Ui {
  18.     class Login;
  19. }
  20. class Login : public QDialog
  21. {
  22.     Q_OBJECT
  23. public:
  24.     explicit Login(QWidget *parent = 0);
  25.     ~Login();
  26. public slots:
  27.     void TOOTAccpted();
  28. protected:
  29.     void changeEvent(QEvent *e);
  30. private:
  31.     Ui::Login *ui;
  32. };
  33. #endif // LOGIN_H







  1. /**************************************************************************
  2. **   Copyright @ 2010 TOOTzoe.com
  3. **   Special keywords: Administrator 2010-7-12 2010
  4. **   Environment variables: %$VARIABLE%
  5. **   To protect a percent sign, use '%'.
  6. **
  7. **
  8. **   E-mail : toot@tootzeo.com
  9. **   Tel    : 13712943464
  10. **   Website: http://www.tootzoe.com
  11. **
  12. **************************************************************************/
  13. //------------------------------------------------------------------------
  14. #include <QMessageBox>
  15. #include "login.h"
  16. #include "ui_login.h"
  17. Login::Login(QWidget *parent) :
  18.     QDialog(parent),
  19.     ui(new Ui::Login)
  20. {
  21.     ui->setupUi(this);
  22. }
  23. Login::~Login()
  24. {
  25.     delete ui;
  26. }
  27. void Login::changeEvent(QEvent *e)
  28. {
  29.     QDialog::changeEvent(e);
  30.     switch (e->type()) {
  31.     case QEvent::LanguageChange:
  32.         ui->retranslateUi(this);
  33.         break;
  34.     default:
  35.         break;
  36.     }
  37. }
  38. void Login::TOOTAccpted()
  39. {
  40.     if(ui->UserName->text() == "toot" && ui->PWD->text() == "cn")
  41.         accept();
  42.     else
  43.         QMessageBox::warning(this,tr("输入法错误...."),tr("请重新输入....."));
  44. }








  1. #include <QApplication>
  2. #include <QTextCodec>
  3. #include "mainfrm.h"
  4. #include "login.h"
  5. int main(int argc, char *argv[])
  6. {
  7.     QApplication app(argc, argv);
  8.     QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  9.     QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
  10.     mainfrm _mainfrm;
  11.     Login login;
  12.     if(login.exec()==QDialog::Accepted  )
  13.        _mainfrm.show();
  14.     else return 1;
  15.     return app.exec();
  16. }
离线buptzhw
只看该作者 1楼 发表于: 2010-07-12
谢谢xtfllbl.
找了一天了,都没有找出上面的问题在哪里?
请求帮助啊
快速回复
限100 字节
 
上一个 下一个