QT-模态对话框获取数据

mydialog.h:




mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QLabel>
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void setting();
private:
    QAction *setAction;
    QLabel *label;
};
#endif // MAINWINDOW_H

mydialog.h:

#ifndef MYDIALOG_H
#define MYDIALOG_H
#include <QDialog>
#include<QString>
namespace Ui {
class myDialog;
}
class myDialog : public QDialog
{
    Q_OBJECT
public:
    explicit myDialog(QWidget *parent = 0);
    ~myDialog();
    QString getProjectPath();
    QString getCompiler();
    QString getColorPlan();
    bool getIndent();
    bool getAutoComplete();
private:
    Ui::myDialog *ui;
};
#endif // MYDIALOG_H

mainwindow.cpp:

#include "mainwindow.h"
#include<QMenuBar>
#include<QToolBar>
#include<QStatusBar>
#include<QAction>
#include "mydialog.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
setAction = new QAction(QIcon(":open.jpg"),tr("选项"),this);
setAction->setStatusTip(tr("环境设定"));
connect(setAction,&QAction::triggered,this,&MainWindow::setting);
QMenu *tool=menuBar()->addMenu(tr("工具"));
tool->addAction(setAction);
QToolBar *toolbar=addToolBar(tr("工具"));
toolbar->addAction(setAction);
QStatusBar *status = statusBar();
status->addAction(setAction);
resize(300,200);
label= new QLabel("",this);
label->setGeometry(0,70,300,140);
}
MainWindow::~MainWindow()
{
}
void MainWindow::setting()
{
myDialog dialog(this);
if(dialog.exec()==QDialog::Accepted)
{
    QString s;
    s="工程目录: "+dialog.getProjectPath()+"\n";
    s=s+"编译环境: "+dialog.getCompiler()+"\n";
    s=s+"高亮显示: "+dialog.getColorPlan()+"\n";
    if(dialog.getIndent())
    s=s+"智能缩进: 是"+"\n";
    else
        s=s+"智能缩进:否"+"\n";
    if(dialog.getAutoComplete())
    s=s+"代码补全:是"+"\n";
    else
        s=s+"代码补全:否"+"\n";
    label->setText(s);
}
}

mydialog.cpp:

#include "mydialog.h"
#include "ui_mydialog.h"
myDialog::myDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::myDialog)
{
    ui->setupUi(this);
}
myDialog::~myDialog()
{
    delete ui;
}
QString myDialog::getProjectPath()
{
QString s=ui->lineEdit->text();
return s;
}
QString myDialog::getCompiler()
{
if(ui->radioButton->isChecked())
    return QString("VC++  6.0");
else if(ui->radioButton_2->isChecked())
    return QString("VC++  2012");
else
    return QString("g++");
}
QString myDialog::getColorPlan()
{
QListWidgetItem *it =ui->listWidget->currentItem();
return it->text();
}
bool myDialog::getIndent()
{
if(ui->checkBox->isChecked())
    return true;
else
    return false;
}
bool myDialog::getAutoComplete()
{
    if(ui->checkBox_2->isChecked())
        return true;
    else
        return false;
}

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值