View Full Version : Creating Widgets

4th February 2006, 15:52
I've noticed that I my widgets will only get shown when I create them at the initialisation of the class(in the constructor, or functions that were (indirectly) called by the constructor. If they're created later, they are(for some strange reason) not shown.
To show what I mean:
class Myclass : public QWidget {
public: Myclass(QWidget *parent=0, const char *name=0); QPushButton *but1, *but2;
protected slots: void createbutton()

Myclass::Myclass(QWidget *parent, const char *name) : public QWidget(parent, name) {
but1 = new QPushButton("click to add button", this);
connect(but1, SIGNAL(clicked()), this SLOT(createbutton()));
void Myclass::createbutton() {
but2 = new QPushButton("but2", this); // Will not be shown
I'm currently creating a dialog, using QPtrList, but I can't add widgets to QPtrList at initialization, because I get the information needed to create the widgets after i'm logged in, and that results in the widgets not being shown. However, when I add some widgets(just to test it) in the constructor, it does show them.
My question is: Is there someway to add the widgets later and still show them(maybe by adding those widgets manually to a QObject list?)?
Thanx in advance,

4th February 2006, 16:00
try show() function

5th February 2006, 08:37
Wow, thanks.
I still can't believe that it could be solved so easily :p