导航:首页 > 编程大全 > linux下qt的sqlite数据库教程

linux下qt的sqlite数据库教程

发布时间:2021-11-25 18:05:55

Ⅰ 到底要怎么在linux下的qt里使用sqlite

使用sqlite的车c/c++ api,去官方网站下载

Ⅱ 请问在Linux系统中QT连接sqlite数据库怎么连接呢查了很多资料,我是初学者,请问高手能详细点指点吗

Ruby 1.8.2
Rails 1.0.0
SQLite 3.3.3
下载 sqlite-3_3_3.zip sqlitedll-3_3_3.zip
解压它们,得到文件sqlite3.exe和sqlite3.dll;
复制它们到目录[RUBY_HOME]/bin下面;
SQLite-Ruby 1.1.0
如下命令安装该模块是针对SQLite 3.x版本
gem install sqlite3-ruby -r -y
SQLite 3.x的可视化工具:SQLite Database Browser
解压它,我们得到软件SQLite Database Browser 1.2.1.exe

Ⅲ vs下的qt怎么操作sqlite数据库

采用将项目中的sqlite文件拷到android内存卡上的固定位置,先判断位置上是否存在sqlite文件,不存在则复制文件。 sqlite可放在res的raw目录下,亦可放在assets下,放在assets下,可新建其他层次目录,本例选择assets 1.首先,添加sdcard权限在An..

Ⅳ 如何用qt使用sqlite数据库,写入变量

采用将项目中的sqlite文件拷到android内存卡上的固定位置,

Ⅳ 到底要怎么在linux下的qt里使用sqlite

你装的只是运行包,需要安装开发包

Ⅵ 在Linux环境里怎么打开一个sqlite的数据库

下载一个Linux 的sqlite3工具(或到SqLite网站下载sqlite的源代码,在你的系统中编译出sqlite3工具),用这个工具打开:
sqlite3 /tmp/test.db

Ⅶ 怎样在Qt下连接读写sqlite数据库

采用将项目中的sqlite文件拷到android内存卡上的固定位置,先判断位置上是否存在sqlite文件,不存在则复制文件。 sqlite可放在res的raw目录下,亦可放在assets下,放在assets下,可新建其他层次目录,本例选择assets
1.首先,添加sdcard权限在AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在activity中有如下代码

2.Java代码

button2.setOnClickListener(new Button.OnClickListener() {

@Override
publicvoid onClick(View arg0) {
try{
String DATABASE_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/testdb"; //将要存放于的文件夹
String DATABASE_FILENAME = "testDatabase.db"; //文件名
String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME;
File dir = new File(DATABASE_PATH);
// 如果/sdcard/testdb目录中存在,创建这个目录
if (!dir.exists())
dir.mkdir();
// 如果在/sdcard/testdb目录中不存在
// test.db文件,则从asset\db目录中复制这个文件到
// SD卡的目录(/sdcard/testdb)
if (!(new File(databaseFilename)).exists()) {
// 获得封装testDatabase.db文件的InputStream对象
AssetManager asset=getAssets();
InputStream is=asset.open("db/testDatabase.db");
FileOutputStream fos = new FileOutputStream(databaseFilename);
byte[] buffer = newbyte[8192];
int count = 0;
// 开始复制testDatabase.db文件
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
asset.close();
}
SQLiteDatabase mSQLiteDatabase=openOrCreateDatabase(databaseFilename, Activity.MODE_PRIVATE, null);//有则打开,没有创建
Cursor cur=mSQLiteDatabase.rawQuery("select * from table1", null);
if(cur!=null){
if(cur.moveToFirst()){
do{
int idColumnIndex=cur.getColumnIndex("id");
int numColumnIndex=cur.getColumnIndex("num");
int dataColumnIndex=cur.getColumnIndex("data");
int id=cur.getInt(idColumnIndex);
int num=cur.getInt(numColumnIndex);
String data=cur.getString(dataColumnIndex);
System.out.println("id:"+id+";num:"+num+";data:"+data);
}while(cur.moveToNext());
cur.close();
}
}
mSQLiteDatabase.close();//关闭数据库连接
}catch(Exception e){
e.printStackTrace();
}
//deleteDatabase("testDatabase.db");//删除数据库
}
});

Ⅷ linux下qt环境,sqlite数据库,如何选择数据

1、数据库直接用QSqlQueryModel 进行读取,显示在一个控件上(eg.tableview->setModel())
2、定义槽函数,实现点击表中元素;槽函数中获取当前的行数,也就获得了当前的数据。
3、把QString添加到lineEdit
大体上就是这样,具体的可以网上搜一下

Ⅸ 请教高手如何使用QT建立SQLite数据库

#include <QtGui>
#include <QtSql>

#include "scooterwindow.h"

ScooterWindow::ScooterWindow()
{
model = new QSqlTableModel(this);
model->setTable("scooter");
model->setSort(Scooter_Name, Qt::AscendingOrder);
model->setHeaderData(Scooter_Name, Qt::Horizontal, tr("Name"));
model->setHeaderData(Scooter_MaxSpeed, Qt::Horizontal, tr("MPH"));
model->setHeaderData(Scooter_MaxRange, Qt::Horizontal, tr("Miles"));
model->setHeaderData(Scooter_Weight, Qt::Horizontal, tr("Lbs"));
model->setHeaderData(Scooter_Description, Qt::Horizontal,
tr("Description"));
model->select();

view = new QTableView;
view->setModel(model);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setColumnHidden(Scooter_Id, true);
view->resizeColumnsToContents();
view->setEditTriggers(QAbstractItemView::NoEditTriggers);

QHeaderView *header = view->horizontalHeader();
header->setStretchLastSection(true);

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view);
setLayout(mainLayout);

setWindowTitle(tr("Scooters"));
}

#ifndef SCOOTERWINDOW_H
#define SCOOTERWINDOW_H

#include <QWidget>

class QSqlTableModel;
class QTableView;

enum {
Scooter_Id = 0,
Scooter_Name = 1,
Scooter_MaxSpeed = 2,
Scooter_MaxRange = 3,
Scooter_Weight = 4,
Scooter_Description = 5
};

class ScooterWindow : public QWidget
{
Q_OBJECT

public:
ScooterWindow();

private:
QSqlTableModel *model;
QTableView *view;
};

#endif

#include <QtGui>
#include <QtSql>

#include "scooterwindow.h"

bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("scooters.dat");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}

void createFakeData()
{
QSqlQuery query;
query.exec("DROP TABLE scooter");

query.exec("CREATE TABLE scooter ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"name VARCHAR(40) NOT NULL, "
"maxspeed INTEGER NOT NULL, "
"maxrange INTEGER NOT NULL, "
"weight INTEGER NOT NULL, "
"description VARCHAR(80) NOT NULL)");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Mod-Rad 1500', 40, 35, 298, "
"'Speedometer, odometer, battery meter, turn signal "
"indicator, locking steering column')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Rad2Go Great White E36', 22, 12, 93, "
"'10\" airless tires')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('X-Treme X360', 21, 14, 59, "
"'Cargo rack, foldable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Vego SX 600', 20, , 76, "
"'Two interchangeable batteries, foldable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Sunbird E Bike', 18, 30, 118, '')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Leopard Shark', 16, 12, 63, "
"'Battery indicator, removable seat, foldable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Vego iQ 450', 15, 0, 60, "
"'OUT OF STOCK')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('X-Treme X-11', 15, 11, 38, "
"'High powered brakes, foldable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('ZZ Cruiser', 14, 10, 46, "
"'Two batteries, removable seat')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('X-Treme X-010', 10, 10, 14, "
"'Solid tires')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Q Electric Chariot', 10, 15, 60, "
"'Foldable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('X-Treme X250', 15, 12, 0, "
"'Solid aluminum deck')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Go MotorBoard 2000X', 15, 0, 20, "
"'Foldable and carryable')");
query.exec("INSERT INTO scooter (name, maxspeed, "
"maxrange, weight, description) "
"VALUES ('Goped ESR750 Sport Electric Scooter', "
"20, 6, 45, " "'Foldable and carryable')");
}

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

bool create = !QFile::exists("scooters.dat");
if (!createConnection())
return 1;
if (create)
createFakeData();

ScooterWindow window;
window.resize(600, 500);
window.show();

return app.exec();
}

阅读全文

与linux下qt的sqlite数据库教程相关的资料

热点内容
微信投票能监测吗 浏览:942
gta5最新版本 浏览:68
java反射执行method 浏览:862
苹果微信语音屏幕变黑 浏览:84
word2007制表位使用 浏览:799
苹果链接不上无线网络连接 浏览:178
matlab处理的最大数据量 浏览:605
javaftp解压zip文件内容 浏览:942
win10系统还原会怎样 浏览:50
电信wifi密码查询 浏览:331
苹果铃声格式在线转换 浏览:219
青海大数据招聘 浏览:307
手机运行内存怎么升级 浏览:126
flashmv源文件免费素材 浏览:904
大数据可视化3d展示 浏览:827
一个完整的网页代码 浏览:486
iphone拍照上下颠倒 浏览:18
javaweb知识 浏览:376
手机触屏幻灯片代码 浏览:135
三国演义英文版本 浏览:360