johnL
12th June 2014, 14:59
I'm new to QT and am trying to develop a database application. To understand step by step, I am Cutting and pasting code from the books example.
The following code from "bookwindow.cpp"
if (!QSqlDatabase::drivers().contains("QSQLITE"))
QMessageBox::critical(this, "Unable to load database", "This demo needs the SQLITE driver");
// initialize the database
QSqlError err = initDb();
if (err.type() != QSqlError::NoError) {
showError(err);
}
compiles and works fine in books example
BUT when copied into mainwindow.cpp for a new QtWidget project compilation fails with message "undefined reference to `QSqlDatabase::drivers()"
When adding the import line ...#include <QtSql>... the include line is highlighted as an error. Tool tip displays "QtSql: No such file or Directory"
However, when typing, QT Creator actually recognises the text and proposes text completion of <QtSql/ and allows selection of <QtSql/QtSql>. Hovering over this gives a tool tip "/home/john/Qt5.2.1/5.2.1/gcc_64/include/QtSql/QtSql"
In contrast, the books example includes the line ...#include <QtSql>... which displays the expected tooltip "/home/john/Qt5.2.1/5.2.1/gcc_64/include/QtSql/QtSql".
Despite QT obviously locating the header files (it proposes text completion) it appears that QT Creator does NOT include the file on compilation, giving rise to the error.
I've looked through the Project files and there do not appear to be any editable project settings for header file directories or any other obvious problem with my code.
Also, entering similar text eg ...#include <QtWidgets>... works correctly, including the header file and QT ackowledges the inclusion in tooltips
Why does Qt not appear to recognise the #include <QtSql> directive? How do I get QT to consistently include headers from the normal header file directories?
Regards
The following code from "bookwindow.cpp"
if (!QSqlDatabase::drivers().contains("QSQLITE"))
QMessageBox::critical(this, "Unable to load database", "This demo needs the SQLITE driver");
// initialize the database
QSqlError err = initDb();
if (err.type() != QSqlError::NoError) {
showError(err);
}
compiles and works fine in books example
BUT when copied into mainwindow.cpp for a new QtWidget project compilation fails with message "undefined reference to `QSqlDatabase::drivers()"
When adding the import line ...#include <QtSql>... the include line is highlighted as an error. Tool tip displays "QtSql: No such file or Directory"
However, when typing, QT Creator actually recognises the text and proposes text completion of <QtSql/ and allows selection of <QtSql/QtSql>. Hovering over this gives a tool tip "/home/john/Qt5.2.1/5.2.1/gcc_64/include/QtSql/QtSql"
In contrast, the books example includes the line ...#include <QtSql>... which displays the expected tooltip "/home/john/Qt5.2.1/5.2.1/gcc_64/include/QtSql/QtSql".
Despite QT obviously locating the header files (it proposes text completion) it appears that QT Creator does NOT include the file on compilation, giving rise to the error.
I've looked through the Project files and there do not appear to be any editable project settings for header file directories or any other obvious problem with my code.
Also, entering similar text eg ...#include <QtWidgets>... works correctly, including the header file and QT ackowledges the inclusion in tooltips
Why does Qt not appear to recognise the #include <QtSql> directive? How do I get QT to consistently include headers from the normal header file directories?
Regards