在qdialog中,我在主窗口中输入了一些我需要的输入,我怎样才能得到它们?我的程序是这样的,我有一个必须在mainwindow之前打开的qdialog,我输入一些输入并单击ok,然后mainwinodw打开使用这些输入。
这是dialog.cpp代码:
#include "dialog.h"
#include "ui_dialog.h"
#include "vtkBMPReader.h"
// Define the length of the volume
void Dialog::bmprange()
{
// Getting some proprieties for the lenght of the volume
QString XMAX=ui->lineEdit->text();
double xMax=XMAX.toDouble();
QString YMAX=ui->lineEdit_2->text();
double yMax=YMAX.toDouble();
QString ZMAX=ui->lineEdit_3->text();
double zMax=ZMAX.toDouble();
QString XMMAX=ui->lineEdit_4->text();
double xMMax=XMMAX.toDouble();
QString YMMAX=ui->lineEdit_5->text();
double yMMax=YMMAX.toDouble();
QString ZMMAX=ui->lineEdit_6->text();
double zMMax=ZMMAX.toDouble();
if (xMax==0 || yMax==0 || zMax==0 || xMMax==0 || yMMax==0 || zMMax==0)
{
ui->label_17->setText("Error: invalid measures");
}
else
{
// Using vtkBMPReader to read all the 128 bmp slices
vtkBMPReader *bmp= vtkBMPReader::New();
bmp->SetDataByteOrderToLittleEndian();
bmp->SetFilePrefix ("/home/matt/Desktop/ouBMP/exemplo");
bmp->SetFilePattern("%s%d.bmp");
bmp->SetFileNameSliceSpacing(1);
bmp->SetNumberOfScalarComponents(3);
bmp->SetDataOrigin(0,0,0);
bmp->SetDataSpacing(xMMax/(xMax-1.0),xMMax/(yMax-1.0),xMMax/(zMax-1.0));
bmp->SetDataExtent(0,xMax-1.0,0,yMax-1.0,1,zMax);
bmp->Update();
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));
ui->lineEdit_2->setValidator(new QIntValidator(this));
ui->lineEdit_3->setValidator(new QIntValidator(this));
ui->lineEdit_4->setValidator(new QDoubleValidator(this));
ui->lineEdit_5->setValidator(new QDoubleValidator(this));
ui->lineEdit_6->setValidator(new QDoubleValidator(this));
connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
connect(ui->lineEdit_2, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
connect(ui->lineEdit_3, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
connect(ui->lineEdit_4, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
connect(ui->lineEdit_5, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
connect(ui->lineEdit_6, SIGNAL(textChanged(QString)), this, SLOT(bmprange()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
如何在主窗口中使用bmp,xMax,...
答案 0 :(得分:1)
我不会说C ++,对于缺乏细节感到抱歉。这就是我要做的事情:
closeEvent
。如果您的对话框中有OK
按钮,则可以使用其clicked
信号。QLineEdit
的文本(例如,QStringList
)和(2)实际关闭你的对话。QStringList
的内容存储为主窗口的属性,或者作为可从主窗口检索的独立对象。