[SOLVED] <QSqlQuery> vs <QtSql/QSqlQuery>
Solved: The qmake module include must be present in all projects using it even indirectly.
I was used to add modules to qmake:
QT += sql
and then including the classes as:
however recently in my plugins/libraries based project I can compile the plugin just fine with the above but when compiling the whole project I get this error:
QSqlQuery: No such file or directory
Oddly simply replacing the include with:
works fine. Why is that? Thx.
Note: I am using Qt 5.3 and the class header that uses this include is located in a shared library so the class is being exported with Q_DECL_EXPORT if that is of any significance.
AFAIK there is no difference but try to use the following instead:
I usually use it for accessing all SQL classes
What do you mean by all project vs plugin ?
On a side note, using module include is a bad habit, while it's ok for rapid prototyping, it should be avoided as it pulls in everything from the module and thus slows down the whole compilation process.
2mbnoimi: All sql family includes do not work when used plainly without the qtsql/ (nor does whole module) directory specified with the same error as in OP.
2SGaist: I have a subdirs project with 2 apps, 3 shared libraries and several dynamic plugins. The problem occurs with one of the libraries. When I compile it on its own (right-click in Creator -> Build/Rebuild) it compiles fine. But when I build one of the apps using it (which also builds the linked libraries) it gives me the error above.
Does each of the sub projects that use the SQL plugin have QT += sql in their .pro files?
When you have a sub project that is a shared library, the shared library requires the Qt module in the .pro as well as the project including files located in the shared library.
I have had to do this before, try adding QT += sql in the .pro file of the app including files from the shared library.
2devz43: Thanks, this solved the problem!