读书人

Qt build时出现如下异常 如何修改哇

发布时间: 2013-07-04 11:45:40 作者: rapoo

Qt build时出现如下错误 怎么修改哇 求大神帮忙 我的Qt版本是5.0.1
Qt  build时出现如下异常  如何修改哇  求大神帮忙 小弟我的Qt版本是5.0.1

代码如下:
main.cpp函数


#include "mainwindow.h"
#include <QApplication>


#include <QtCore/QCoreApplication>
#include <QtSql>
#include <QDebug>

int main(int argc, char *argv[])
{
//QApplication a(argc, argv);


QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/tmp/my.db");
if (!db.open())
{
qDebug()<<"open database failed ---"<<db.lastError().text()<<"/n";
return -1;
}
QSqlQuery query;
bool ok = query.exec("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT,"
"name VARCHAR(20) NOT NULL,"
"age INTEGER NULL)");
if (ok)
{
qDebug()<<"ceate table partition success/n";
}
else
{
qDebug()<<"ceate table partition failed/n";
}
for (int i = 0; i< 3; ++i)
{
query.prepare("INSERT INTO people (id, name, age) VALUES (:id, :name, :age)");
query.bindValue(":name", QString("smith_%1").arg(i+1));
query.bindValue(":age", 20+i*5);
query.exec();
}

query.exec("SELECT id, name, age FROM people");
while (query.next())
{
qDebug()<<"people("<<query.value(0).toInt()<<") name:"<<query.value(1).toString()<<" age:"<<query.value(2).toInt();
}

MainWindow w;
w.show();

return a.exec();



.pro文件内容:


QT += core gui
QT += core sql
QT -= gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = sqlite
TARGET = sql
CONFIG += console
CONFIG -= app_bundle
LIBS += -lsqlite3
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp



HEADERS += mainwindow.h

FORMS += mainwindow.ui Qt GUI 数据库 SQL 应用
[解决办法]
你有安装sql吗?
找不到lsqlite3啊
[解决办法]
sqlite是Qt内置的,只要启用sql模块即可直接使用,发布程序的时候带上dll。
[解决办法]

引用:
内置的 为什么还提示没有呢 还有第二个错误是怎么回事呀

应该下载一个好一些的Qt版本,会有sqlite3的。此外第二个错误是因为第一个错误引起的。

读书人网 >QT开发

热点推荐