PDA

View Full Version : I want to view my QTextEdit from class A in mainLayout in class B.



inger
18th August 2011, 14:31
How is it possible?
I have a project with several classes. In class A I make the layout. In class B I get the signals and make a QTextEdit, named received_msg, that I want to show in class A' s layout, called mainLayout.

How is it possible?

How can I make the connection?

mvuori
18th August 2011, 17:44
You ask the object of class A (let's call it ObjectA) a pointer to its layout B->layoutPointer = ObjectA->layout() ... or something similar, if ObjectA created it somewhere else.

After that you just add your field to that layout B->layoutPointer->addWidget(B->received_msg).

inger
19th August 2011, 08:44
Thanks.

I really dont understand what to do. Will you please help me further.
:confused:
my main() is:


#include <QtGui/QApplication>
#include "overfore.h"
#include "vindu.h"
#include <QObject>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Overfore ov;
return a.exec();
}

my overfore.cpp is:



#include "overfore.h"
#include "ui_overfore.h"

Overfore::Overfore(QWidget *parent) :
QWidget(parent),
ui(new Ui::Overfore)
{
ui->setupUi(this);
textOverfore = new QTextEdit;
textOverfore->append("Hello");
Vindu *vindu = new Vindu;
vindu->layout();
}


and my vindu.cpp is:


#include "vindu.h"

Vindu::Vindu(QWidget *parent) :
QWidget(parent)
{
QPushButton *button = new QPushButton("button");
textfield = new QTextEdit;
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(button);
buttonLayout->addWidget(textfield);

setLayout(buttonLayout);
setVisible(buttonLayout);
}

What I really want is when I push "button" in class Vindu, I want the "textfield" from class Overfore to be shown in the field textOverfore in object vindu class Vindu. The variables are defined in the header files.:confused: