Results 1 to 3 of 3

Thread: I want to view my QTextEdit from class A in mainLayout in class B.

  1. #1
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question I want to view my QTextEdit from class A in mainLayout in class B.

    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?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: I want to view my QTextEdit from class A in mainLayout in class B.

    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).

  3. #3
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I want to view my QTextEdit from class A in mainLayout in class B.

    Thanks.

    I really dont understand what to do. Will you please help me further.

    my main() is:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "overfore.h"
    3. #include "vindu.h"
    4. #include <QObject>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. Overfore ov;
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    my overfore.cpp is:

    Qt Code:
    1. #include "overfore.h"
    2. #include "ui_overfore.h"
    3.  
    4. Overfore::Overfore(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::Overfore)
    7. {
    8. ui->setupUi(this);
    9. textOverfore = new QTextEdit;
    10. textOverfore->append("Hello");
    11. Vindu *vindu = new Vindu;
    12. vindu->layout();
    13. }
    To copy to clipboard, switch view to plain text mode 

    and my vindu.cpp is:

    Qt Code:
    1. #include "vindu.h"
    2.  
    3. Vindu::Vindu(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. QPushButton *button = new QPushButton("button");
    7. textfield = new QTextEdit;
    8. QHBoxLayout *buttonLayout = new QHBoxLayout;
    9. buttonLayout->addWidget(button);
    10. buttonLayout->addWidget(textfield);
    11.  
    12. setLayout(buttonLayout);
    13. setVisible(buttonLayout);
    14. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by inger; 19th August 2011 at 07:51.

Similar Threads

  1. Replies: 7
    Last Post: 18th August 2011, 14:43
  2. Replies: 3
    Last Post: 27th December 2008, 19:34
  3. Replies: 3
    Last Post: 16th May 2007, 11:07
  4. Model/View: Use own class with QVariant
    By No-Nonsense in forum Qt Programming
    Replies: 5
    Last Post: 18th December 2006, 17:21
  5. QTDesigner base view class
    By dave in forum Newbie
    Replies: 1
    Last Post: 14th November 2006, 21:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.