[Qt-interest] Refactoring app to use QStackedWidgets with opaque widget pointers, rather than one large QStackedWidgets to cut compilation dependencies
John Moran
johnfrederickmoran at gmail.com
Fri Nov 27 14:54:18 CET 2009
Hello,
I'm working on an Qt embedded application, that mostly consists of a
single QWidget that displays a QStackedWidget. Each page of the
stacked widget consists of collections of widgets like QPushButtons
and so on. As the number of pages has increased, we've had problems
with cascading compilation dependencies - I have to include the UI
file's header in my "mainwidget"'s header. Although I've spread the
implementation of the "mainwidget" (the functions that it's slots are
connected to) across multiple CPP files, any time that I change the UI
through Qt designer I have to recompile the whole class (about 7
translation units). Declaring but not defining the class in the header
(having an opaque pointer to it), and including the header in each CPP
file doesn't really help, because it's needed in all CPP files anyway.
Each translation unit (CPP file) of "mainwidget"'s implementation
usually corresponds to a different page, so the functionality is
logically partitioned that way.
One possible fix is to have the existing UI file's stacked widget just
contain other UI classes (that are somehow opaque; i.e. had their UI
classes declared but not defined). We then have a bunch of opaque
pointers in "mainwidget"'s definition; the existing UI, plus a bunch
of them for each page's UI class. We then selectively include only
those definitions that are needed in each CPP file of "mainwidget"'s
implementation, and avoid having to re-compile the entirety of the
rather large, multiple translation unit file every time I change my
main .ui file.
That way, rather than doing this:
// in translation unit mainwidget_firstpage.cpp
void mainwidget::something()
{
mymainscreen.logo->setPixmap(my_pixmap);
}
I do this:
void mainwidget::something()
{
mymainscreen.first_page->logo->setPixmap(my_pixmap);
}
Is this possible? If so, how? Obviously, if the .h file generated by
the newly partition mainwidget UI file (the one that contains the
others) cannot be made to declare its classes as opaque pointers,
doing this won't help. That said, I could just have UI files for the
page widgets, and forget about having a UI file for my original
QStackedWidget containing UI class - just write the .h file by hand.
What are your thoughts?
Thanks a lot,
John Moran
More information about the Qt-interest-old
mailing list