Jos*_*eph 3 c++ sqlite qt class
我有使用C++的经验,但我以前从未真正使用过Qt.我正在尝试连接到SQLite数据库,所以我在这里找到了一个教程并且正在使用它.在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();
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
main.cpp:13: error: request for member 'openDB' in 'db', which is of non-class type 'DatabaseManager()'
Run Code Online (Sandbox Code Playgroud)
谁能指出我正确的方向?我知道"copypaste"代码不好,我只是想知道我是否可以使数据库连接工作,我觉得这样的事情很简单...感谢您的帮助.
将DatabaseManager行更改为:
DatabaseManager db;
Run Code Online (Sandbox Code Playgroud)
你声明一个名为local的函数db
,它不带参数,并DatabaseManager
在你提供时返回一个对象()
;