That is a terrible video, and I would be very cautious about using any of that poster's videos as a guide. Just two of the things I saw that were serious errors:
1 - He defined his stack widget page widgets as automatic member variables of the Application class. (i.e. MachineState machineState; instead of MachineState * machineState). No QWidget instance should ever be declared in this way; instead they should be declared as pointer variables, constructed on the heap (using new()) and given an appropriate parent:
// .h
class MachineState;
class Settings;
{
Q_OBJECT;
// ...
private:
MachineState * machineState;
Settings * settings;
};
// .cpp
Application
::Application( QWidget * parent
)// ...
{
ui->setupUi( this );
machineState = new MachineState( this );
settings = new Settings( this );
//...
}
// .h
class MachineState;
class Settings;
class Application : public QWidget
{
Q_OBJECT;
// ...
private:
MachineState * machineState;
Settings * settings;
};
// .cpp
Application::Application( QWidget * parent )
: QWidget( parent )
// ...
{
ui->setupUi( this );
machineState = new MachineState( this );
settings = new Settings( this );
//...
}
To copy to clipboard, switch view to plain text mode
with this code, the two sub-widgets are owned by the Application instance and will be appropriately destroyed when Application is destroyed.
2 - He doesn't use layouts for any of the page widgets, and he puts the control widgets on the forms with absolute positions and sizes. This will result in ugly behavior when the application widget is resized.
There are probably more things that would make me ill, but just watching that much made me sick enough.
Maybe you know enough to use better coding practices than the ones in this video, but if you thought that what you saw was just fine to imitate, well, don't do that. Study the Qt tutorials and examples for much better solutions.
Bookmarks