Reputation: 145
For historical reasons, we need to keep our software compatible with Qt 4.8. The current branch is built on Qt 5.2.
Recently I have been trying to exploit the new features of some of the QWidget, like QAbstractScrollArea::setSizeAdjustPolicy. Unfortunately, when I do that, I cannot compile in Qt 4.8 and Visual Studio produce the following error
error C2039: 'AdjustToContents' : is not a member of 'QAbstractScrollArea'
Usually, I would use a precompiler directive to adapt the code for each version. In this case however, I cannot do that since qt designer is generating a .ui file which generates code on the fly.
Is there a way to let Qt know that I want to exclude some nodes of the .ui file when compiling?
Upvotes: 1
Views: 690
Reputation: 98505
The .ui
file is just an xml file. It is converted to code by uic
. The generated code is specific to a build with a particular version of Qt, you cannot reuse the same build directory and thus uic output with multiple Qt installations. Uic output should not be in your source code repository.
The error you get indicates that you're using output from Qt 5.6's uic with Qt 4. This is not ever supposed to work.
Instead, you should do a clean build of your code using Qt 4, and there, most likely, uic might either ignore, warn or abort on unknown elements/attributes. If it does abort, it's easy enough to modify uic not to do that (a couple lines have to be changed).
If you're using Qt professionally, you're already building your own copy that you maintain, so patching uic should be a trivial thing to add to your process.
Upvotes: 1
Reputation: 1123
When you build using qmake you might consider the following snippet
greatherThan(QT_MAJOR_VERSION, 4) {
FORMS += # qt 5 forms goes here
INCLUDEPATH += # path to qt 5 forms
} else {
FORMS += # qt 4 forms goes here
INCLUDEPATH += # path to qt 4 forms
}
Then, considered the files are called the same and placed in different, version specific directories, you should easily use them in your source files.
Querying the value of QT_VERSION might enable you to react on minor version changes. Hence you should use contains(...) and some proper regular expression.
I scrubbed my head a lot but could not come up with a solution where you have one ui file which changes with the used Qt version. Maybe you could do some XML preprocessing in your toolchain...
Upvotes: 0