いくつかのスライスの長さ (xmax、ymax、および zmax をスライスの数として) を求めるダイアログを作成しました。これらの数値を qvtkwidget のメインウィンドウで使用するつもりです。理解して助けていただけるように、例を単純化して変数を 1 つだけにします。
これが私のdialog.cppです
#include <QtGui/QApplication>
#include <QDir>
#include <iostream>
using namespace std;
#include "dialog.h"
#include "ui_dialog.h"
// Create getters to transfer variables to main.cpp
double Dialog::getxpax()
{
return xpax;
}
// Start the mainwindow
void Dialog::startplanevolume()
{
// Getting some proprieties for the lenght of the volume
QString XMAX=ui->lineEdit->text();
xpax=XMAX.toDouble();
if (xpax==0)
{
ui->label_17->setText("Error: Can't start, invalid \nmeasures");
ui->label_17->setStyleSheet("QLabel { color : red; }");
}
else
{
this->accept();
}
}
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 QDoubleValidator(this));
// Start planevolume
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(startplanevolume()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(hide()));
}
pushbutton は ok ボタンで、pushbutton_2 はキャンセル ボタンです。
メインウィンドウで、xmax の値を設定するセッター関数を作成しました。
ここにいくつかのコードがあります。
// Get stored data from dialog
void planevolume::setxpax(double xpax)
{
xp=xpax;
}
qDebug() を使用すると、セッター内の xp は、xp が実際に xpax 値を取得することを示しています。
ここに私のmain.cppがあります
#include <QtGui/QApplication>
#include <iostream>
using namespace std;
#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.setxpax(dialog->getxpax());
mainwindow.show();
return app.exec();
}
return 0;
}
したがって、唯一の問題は、必要なときに mainwindow で planevolume.cpp としてここにあることです。値は設定されていません。
planevolume::planevolume(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::planevolume)
{
ui->setupUi(this);
// My vtk statements are here in the code, but they are
// executed before the setter gives the value to my new
// variable xp, so when I need the value it has not been set yet.
アイデアはありますか?