SimonH
SimonH

Reputation: 1415

QWidgets as members or not?

I just started to learn how to use Qt and I wonder if I should describe the Widgets (e.g. an array of Pushbuttons) in the QMainFrame class as private members or should I define them in the constructor of QMainFrame? What's the common implementation and what are the (dis)advantages of both ways?

Upvotes: 1

Views: 44

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73041

If you need to access them later on in the program's execution, it's often convenient to have private member variables which point to the QPushButtons, so that you have quick and easy access to them. If you don't need to call methods on the QPushButtons directly (e.g. because everything can be set up inside the constructor by connecting various signals and slots) then there is no need for them to be member variables, and you can save memory and simplify your program by not adding member variables.

Upvotes: 2

Related Questions