PDA

View Full Version : Parents of (Tab)Widgets when using Eclipse QT Plugin



chrisQL
7th June 2011, 14:30
I'm very new to QT, but used to Eclipse, so I love the Eclipse QT Plugin, but now here is something I don't understand and I was hoping you could help me:

My understanding of the plugin so far is, that I click together my gui, which is saved in an XML file (say: myprog.xml) and by some higher magic transformed into C++ code (ui_myprog.h) that describes where to put the elements and what to do with them.

I have a simple application containing a QTabWidget that has 2 tabs, containing my own Widgets called InputTab and PreprocessingTab. When I look in the automatically created ui_myprog.h, it creates this QTabWidget like this:



tabWidget = new QTabWidget(SmyrnaClass);
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
tabWidget->setGeometry(QRect(0, 0, 1011, 781));
tabWidget->setTabPosition(QTabWidget::West);
tabWidget->setTabShape(QTabWidget::Rounded);
inputTab = new InputTab();
inputTab->setObjectName(QString::fromUtf8("inputTab"));
tabWidget->addTab(inputTab, QString());
preprocessingTab = new PreprocessingTab();
preprocessingTab->setObjectName(QString::fromUtf8("preprocessingTab"));
tabWidget->addTab(preprocessingTab, QString());


My own class for InputTab has a predefined constructor like this:


InputTab(QWidget *parent = 0);

and I found out that it is indeed constructed without a parent. However, later in other methods of InputTab I am able to access its parent (the QTabWidget) and its grandparent (MyProg). However, I don't see where the parent was set. This should be done in ui_myprog.h, but I see nothing like this. I observed this problem when I was trying to access the parent in the constructor, where it is still undefined. Now I wonder what I have to do to make sure the parent really is set. Would be great if someone could help me out :-/

Santosh Reddy
7th June 2011, 14:41
tabWidget->addTab(inputTab, QString());
tabWidget->addTab(preprocessingTab, QString());
When you insert the widget into a QTabWidget, QTabWidget takes ownership (becomes parent) of the widget (which is inputTab/preprocessingTab in your case)

chrisQL
7th June 2011, 14:57
Ah, that explains a lot ... thank you!!