how to pass ui::windows as parameter.
-
wrote on 6 Apr 2015, 13:10 last edited by rafael 4 Jun 2015, 13:21
i have multiple windows created from ui_designer.
window 1 for example is ui::window1 *ui
and window 2 is ui::window2 *uii 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 *uifooter( **** 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
{}
-
If
common
is a base class then it makes no sense that it would know about members of derived classes (theui
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 yourcommon
class access the button viacloseButton
method.
1/2