[SOLVED]Usage of "this" unknown in calling setupUi()



  • May be this is due to my weak concepts in c++...In Qt i often see this line ui.setupUi( this ); or
    ui->setupUi(this) ;. I understand that , ui is the object that is used to call the function setupUI(). But i don't understand , what is "this"?? y is it passed to setuUi() ??



  • "this" means the "current class" where the code was written.

    ui->setupUI(this); needs a pointer of the current class (mainwindow) to be able to populate it with widgets. this pointer is needed since it will become a parent to the widgets you want to add.

    In Qt Creator, try hovering your mouse to setupUI() then press F2. you will be sent to the implementation.



  • [quote author="Code_ReaQtor" date="1358310836"]"this" means the "current class" where the code was written.
    . this pointer is needed since it will become a parent to the widgets you want to add.

    [/quote]
    Thanks a lot, you gave me the exact explanation .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.