PDA

View Full Version : Connection of two own widgets



Phalanx
16th April 2010, 15:17
Hi, I have a problem with connection my widgets. This is pseudocode:

mainwindow.cpp:
(my own widgets)
FileWidget *My_Files = new FileWidget(this);
TableWidget *My_Table = new TableWidget(this);

then I have files for filewidget and tablewidget
*.cpp *.h *.ui

I need in filewidget.cpp use something like ui->TableWidget->addTab()
I including into filewidget.cpp tablewidget.h and tablewidget.ui... but I must not create another instance of tableWidget.

Thank you for replies

borisbn
16th April 2010, 16:09
If you want to do so, you should give a pointer or reference to class TableWidget to class FileWidget
e.g.


TableWidget *My_Table = new TableWidget(this);
FileWidget *My_Files = new FileWidget( this, My_Table );

FileWidget::FileWidget( QWidget * parent, TableWidget * a_TableWidget )
: QWidget( parent ), m_TableWidget( a_TableWidget )
...

and in FileWidget you can do:


m_TableWidget->addTab()

Phalanx
16th April 2010, 16:43
Thank you, this is exactly what I need. I try it, but in filewidget.h I have error in this.
Constructor in *.h file:
FileWidget(QWidget *parent = 0, TableWidget *a_TableWidget); -- this is wrong

aamer4yu
16th April 2010, 16:50
Did you include classes properly ?
Does FileWidget know about TableWidget ??

Phalanx
16th April 2010, 16:53
I am tool... FileWidget(QWidget *parent = 0, TableWidget *a_TableWidget = 0);

Phalanx
16th April 2010, 17:05
I love you guys :D Works perfectly :) I spend 2 days on it