Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass arguments to constructor of widget within QStackedWidget

I have a graphical application written in C++ using Qt for an embedded device, which uses a QStackedWidget holding a number of UI widgets. The UI is all designed in Qt Creator's designer tool. When the user navigates through the device's application the display to be shown at that menu option is selected from the QStackedWidget and this all works great.

I'm now wanting to pass in a pointer to some configuration which is read from file when the application starts, but I can't seem to find a way to pass this pointer as an argument into the constructor of a widget on the QStackedWidget. Can anyone help?

My current approach is to call a function I've written within the class of a widget on the QStackedWidget, which works but doesn't feel the best way to do it.

like image 535
SionHughes Avatar asked Oct 22 '25 23:10

SionHughes


1 Answers

To my knowledge if you want to use custom constructors - with other kinds of arguments than just the QWidget * parent - you have to create the ui programmatically:

  • create your custom StackedWidget with a special constructor,
  • prepare the global interface using the designer,
  • then add the StackedWidget in the constructor of the class after the setupUi method.

The other way is to use an initialization method after the construction of the item, like you did.

like image 192
Davy Avatar answered Oct 27 '25 01:10

Davy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!