View Full Version : getting data from a Dialog
graciano
20th August 2009, 18:04
Hi
I'm using public member-functions to get data from a called Dialog.
#ifndef A_H
#define A_H
#include <QtGui/QDialog>
namespace Ui {
class a;
}
class a : public QDialog {
Q_OBJECT
public:
a(QWidget *parent = 0);
~a();
QString getA();
protected:
void changeEvent(QEvent *e);
private:
Ui::a *m_ui;
};
#endif // A_H
Calling the Dialog ...
void Dialog::calla()
{
a x;
x.exec();
ui->a_lineEdit->setText(x.getA());
}
Could someone point me other ways to do this!
Thanks
franz
21st August 2009, 06:53
I think you have chosen the best way to obtain data from a class; by using a getter function.
However, since you seem to want to synchronize the text in two widgets, you can consider connecting a textChanged() signal from your dialog to the lineEdit's setText() slot. In your case that wouldn't really reduce your code, though.
graciano
21st August 2009, 15:56
And if i want this working the opposite direction?
Let's say i want that objects created from class a get some data from de base class.
This is a constructor issue ... isn'it?
#include "a.h"
#include "ui_a.h"
a::a(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::a)
{
m_ui->setupUi(this);
m_ui->label.setText("data from the calling dialog!?!");
}
Lykurg
21st August 2009, 16:49
read about setter and getter functions. In your case it would be like:
class a : public QDialog {
Q_OBJECT
public:
//...
void setSomeThing(QString str);
};
void a::setSomeThing(QString str)
{
// if needed check the content of str
ui->someLineEdit->setText(str);
}
graciano
21st August 2009, 16:59
yess ... but the content of that str is somewhere in other Dialog that called this one.
Am i missing something obvious?
Lykurg
21st August 2009, 17:53
Am i missing something obvious?
Yes ;-)
void Dialog::calla()
{
a x;
x.setSomeThing("foo bar");
x.exec();
ui->a_lineEdit->setText(x.getA());
}
graciano
21st August 2009, 20:37
Wellll ... guess i need vacations.
"I'll be back :cool:"
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.