[Qt-creator] Qt Quick UI example code

Daniel Teske Daniel.Teske at theqtcompany.com
Fri Oct 31 12:51:57 CET 2014


On Friday 31 Oct 2014 12:41:44 John Idarraga wrote:
> Hello all,
> 
> I downloaded the last version of QtCreator (3.2.2 Built on Oct 10 2014
> 11:17:04 From revision 34971be5cc).  I proceed to start a new
> Application project  --> Qt Quick UI.  The template code generated for
> the constructor of the class goes as follows
> 
> SpidrMpx3Eq::SpidrMpx3Eq(QWidget *parent) :
>      QMainWindow(parent),
>      ui(new Ui::SpidrMpx3Eq)
> {
>      ui->setupUi(this);
> }
> 
> if for instance i want to connect a signal to a slot for a given object
> I need to do
> 
> connect( ui->_myButton, .... )
> 
> My question is.  Why not letting the Ui setup by doing
> 
> this->setupUi(this);
> 
> and then simply use the inherited public member "_myButton"
> 
> connect( _myButton, .... )
> 
> what's the use for the ui pointer here ?
> 
Whether you prefer Ui::SpidrMpx3Eq as a base class or as a member depends on 
how you view the SpidrMpx3Eq class. 

In our code we usually prefer to have the details on how the ui is implemented 
to be encapsulated, and to then offer a api tailored to the purpose of the 
class. 

daniel




More information about the Qt-creator mailing list