You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, February 23rd 2012, 8:55pm

Can’t add widget created by Designer

Hello,

I'm trying to make widget with Designer and add it to main window.
There is vertical layout withing main window.
I've created widget with Wizard (Add new->Qt->Qt Designer Form Class). It's name id "Fuel_widget".

here is the code which tries to add widget to main window:
main.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
     app.setOrganizationName("DART Private");
     app.setApplicationName("VGA");
 
     MainWindow *window = new MainWindow;
 
Fuel_widget *f = new Fuel_widget(w);
 
     window->AddWidget(f);
 
     window->show();
 
     return app.exec();
 }



mainwindow.cpp

Source code

1
2
3
4
 void MainWindow::AddWidget(QWidget *widget)
 {
     ui->verticalLayout->addWidget(widget);
 }


Nothing shows up when I execute that :(

But manually (without Designer-created code) created widgets work well:

Source code

1
2
     QPushButton *b = new QPushButton("aaa");
     window->AddWidget(b);


the answer is near but I can't figure it out :(
help, please.

2

Friday, February 24th 2012, 12:28am

you say you made a widget Fuel_widget. How do we know you put anything on it?

read my sig, I know you are making up code:

Fuel_widget *f = new Fuel_widget(w); <--- what is w?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Friday, February 24th 2012, 9:41pm

sorry, I've cleared my code more than I wanted.

"w" is

Source code

1
QWidget *w = new QWidget;


"How do we know you put anything on it?"

Creator made code that put anything needed on it

that code is called in Fuel_widget constructor with call to ui->setupUi(this);

4

Friday, February 24th 2012, 11:21pm

read my sig. Post a simple example of what you are ACTUALLY compiling.

"Creator made code that put anything needed on it"
Great, if you say so. Then there is no problem and the code and creator is just doing what you asked. So there is no problem, right?

If I say how do we know you put anything in that widget, then it means you need to SHOW US, not say "it's fine". If you say "it's fine", then I say to you: Creator and Qt are just doing what you tell it. So that means you are telling it to show 'nothing'
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar threads