【发布时间】:2010-06-10 03:20:24
【问题描述】:
我有使用 C++ 的经验,但我以前从未真正使用过 Qt。我正在尝试连接到 SQLite 数据库,所以我找到了一个教程 here 并继续使用它。在 QtCreator IDE 中,我转到 Add New --> C++ Class 并在头文件中粘贴来自该链接的头文件,并在 .cpp 文件中粘贴源代码。我的 main.cpp 看起来像这样:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "databasemanager.h"
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
DatabaseManager db();
QLabel hello("nothing...");
if(db.openDB()){ // Line 13
hello.setText("Win!");
}
else{
hello.setText("Lame!");
}
hello.resize(100, 30);
hello.show();
return a.exec();
}
我收到了这个错误:
main.cpp:13: error: request for member 'openDB' in 'db', which is of non-class type 'DatabaseManager()'
谁能指出我正确的方向?我知道“复制粘贴”代码不好,我只是想看看我是否可以让数据库连接正常工作,我认为这样的事情会很简单......感谢您的帮助。
【问题讨论】: