上述回答采纳不采纳,我不强求 ,
只求能帮助到楼主。
若需要帮助,本人可为您效仿。
远程帮助为您排难解忧解决你的担心的问题
若回答不准确可以追问 我们可以互相探讨下。
小女子,祝您合家欢乐,心想事成。
万事顺心
谢谢!function getGithunZen() {
var url = ">
供参考:
maincpp 文件
#include <QApplication>#include "clogindialogh"
int main(int argc, char argv[])
{
QApplication app(argc, argv);
CLoginDialog loginDlg = new CLoginDialog();
loginDlg->show();
return appexec();
}
clogindialogh 文件
#define CLOGINDIALOG_H
#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QLayout>
class CLoginDialog : public QDialog
{
Q_OBJECT
public:
explicit CLoginDialog(QWidget parent = nullptr);
private slots:
void showMainWindow();
private:
QComboBox userTypeCombo;
};
#endif // CLOGINDIALOG_H
clogindialogcpp 文件
#include "clogindialogh"#include "cwidgetah"
#include "cwidgetbh"
CLoginDialog::CLoginDialog(QWidget parent) : QDialog(parent)
{
QHBoxLayout lineLayout1 = new QHBoxLayout();
lineLayout1->addWidget(new QLabel(tr("登录类型")));
userTypeCombo = new QComboBox();
userTypeCombo->addItem(tr("教师"),0);
userTypeCombo->addItem(tr("学生"),1);
lineLayout1->addWidget(userTypeCombo);
QHBoxLayout lineLayout2 = new QHBoxLayout();
lineLayout2->addStretch();
QPushButton loginBt = new QPushButton(tr("登录"));
connect(loginBt,&QPushButton::clicked,this,&CLoginDialog::showMainWindow);
lineLayout2->addWidget(loginBt);
QVBoxLayout mainLayout = new QVBoxLayout();
mainLayout->addLayout(lineLayout1);
mainLayout->addLayout(lineLayout2);
setLayout(mainLayout);
}
void CLoginDialog::showMainWindow()
{
if(userTypeCombo->currentData() == 0){
CWidgetA a = new CWidgetA();
a->show();
}else{
CWidgetB b = new CWidgetB();
b->show();
}
close();
}
cwidgetah 文件
#define CWIDGETA_H
#include <QMainWindow>
class CWidgetA : public QMainWindow
{
Q_OBJECT
public:
explicit CWidgetA(QWidget parent = nullptr);
};
#endif // CWIDGETA_H
cwidgetacpp 文件
#include "cwidgetah"#include <QLabel>
CWidgetA::CWidgetA(QWidget parent) : QMainWindow(parent)
{
setCentralWidget(new QLabel(tr("这是窗口A")));
}
cwidgetbh
#ifndef CWIDGETB_H
#define CWIDGETB_H
#include <QMainWindow>
class CWidgetB : public QMainWindow
{
Q_OBJECT
public:
explicit CWidgetB(QWidget parent = nullptr);
};
#endif // CWIDGETB_H
cwidgetbcpp
#include "cwidgetbh"#include <QLabel>
CWidgetB::CWidgetB(QWidget parent) : QMainWindow(parent)
{
setCentralWidget(new QLabel(tr("这是窗口B")));
}if (false == ui->LineEdit->text()isEmpty()){
//允许登录
}
else{
QMessageBox::warning(this, tr("WindowTitle"), tr("Empty Input String"));
}
用QLineEdit控件作为密码输入的话参照上面代码即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)