我已经创建了dialog.h、dialog.cpp和dialog.ui文件,并在对话框中添加了qlineedit,以及ok和cancel按钮。我想将这些linedit信息存储起来,在不同的文件中的mainwindow中使用。以下是我的对话框代码。
#include <QtGui/QApplication>
#include "dialog.h"
#include "ui_dialog.h"
void Dialog::startplanevolume()
{
if (xMax==0)
{
ui->label_17->setText("Error: Can't start, invalid \nmeasures");
}
else
{
this->accept();
}
}
// Define the length of the volume
void Dialog::bmprange()
{
// Getting some proprieties for the lenght of the volume
QString XMAX=ui->lineEdit->text();
xMax=XMAX.toDouble();
if (xMax==0)
{
ui->label_17->setText("Error: invalid measures");
}
else
{
ui->label_17->setText("Valid measures");
}
}
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
// Control volume measures
// Making the lineedit objects only accept numbers
ui->lineEdit->setValidator(new QIntValidator(this));
connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
// Start planevolume
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(startplanevolume()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(hide()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
我该如何在mainwindow.cpp中使用xMax的值?
这是我的dialog.h:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog {
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
protected:
void changeEvent(QEvent *e);
private:
Ui::Dialog *ui;
double xMax, yMax, zMax, xMMax, yMMax, zMMax, list[6];
public slots:
void bmprange();
void startplanevolume();
};
#endif // DIALOG_H
这是我的main.cpp文件
#include <QtGui/QApplication>
#include "planevolume.h"
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog *dialog= new Dialog;
if (dialog->exec())
{
planevolume mainwindow;
mainwindow.show();
return app.exec();
}
return 0;
}
那么我想在mainwindow中使用xMax来计算planevolume.cpp中的某些内容。
xMax
是如何定义的,它在哪里定义的?你是如何调用这个对话框的?你是在什么时候和地方创建它的? - rpsml