how to pass ui::windows as parameter.



  • i have multiple windows created from ui_designer.

    window 1 for example is ui::window1 *ui
    and window 2 is ui::window2 *ui

    i want to update labels items located on the status bar for each indiviual ui.

    i created a class that has common code for all ui.

    is there a generic paremeter which i can pass to the function to make it take any ui or i just have to override each function to take a different window.

    ie ui::window1 *ui
    ui::window2 *ui

    footer( **** ui ****)
    {
    QPixmap cimage = QPixmap(":/images/OnOff.png");
    ui->closebutton->setPixmap(cimage);
    }

    each window inherits from the common class qobject.

    class Mainwindow : public QMainWindow, public common
    {

    }


  • Moderators

    If common is a base class then it makes no sense that it would know about members of derived classes (the ui member). The type of that member is different for each derived class and they don't have a common base class so you can't get a "universal" pointer to it (apart from void* which you should definitely not do).

    One way to arrange this is make a pure virtual method in common that will return a button pointer i.e. virtual QPushButton* closeButton() = 0. then, in each derived class implement that method to return the button from its ui member. In your common class access the button via closeButtonmethod.


Log in to reply
 

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