0

In qdialog i put some input that i need in the mainwindow, how can i get them? my program is something like this, I have a qdialog that must open before mainwindow, I put there some input and click ok, and then the mainwinodw opens using those inputs.

here's the dialog.cpp code:

#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;
    }
}

how can i get bmp, xMax, ... to use in mainwindow

SamuelNLP
  • 4,038
  • 9
  • 59
  • 102

1 Answers1

1

I don't speak C++, so sorry for the lack of details. Here's what I'd do:

  • Catch the closeEvent that you should have when you close your dialog. If your dialog has a OK button, you can use its clicked signal.
  • Connect it to a particular slot whose functions are (1) to retrieve the texts of all your dialog's QLineEdit in a single object (a QStringList, for example) and (2) to actually close your dialog.
  • Store the content of this QStringList as an attribute of your main window, or as an independent object you can retrieve from your main window.
Pierre GM
  • 19,809
  • 3
  • 56
  • 67
  • the problem is that dialog and mainwindow are in different files – SamuelNLP Aug 30 '12 at 08:52
  • yould it just be to include "dialog.h" in plainvolume.cpp? – SamuelNLP Aug 30 '12 at 08:59
  • Can't you define some kind of common module where to store your signals? – Pierre GM Aug 30 '12 at 09:01
  • I created a function as a slot and the slot is like this `void Dialog::getvalues() { double list[6]; list[0]=xMax; list[1]=yMax; list[2]=zMax; list[3]=xMMax; list[4]=yMMax; list[5]=zMMax; }` – SamuelNLP Aug 30 '12 at 09:20
  • and added dialog.h as an include in planevolume.cpp, and then I call it as Dialog::getvalues(); but i get that i can't call a function without object. – SamuelNLP Aug 30 '12 at 09:21