简体   繁体   English

如何使用预加载的数据库运送必需品或qt项目

[英]How to ship a necessitas or qt project with a preloaded database

Is there any way to add a preloaded sqlite database to a necessitas or qt project? 有没有办法将预装的sqlite数据库添加到必需品或qt项目? I try to copy it directly to /data/data/my_project/files7 in the emulator and I dont have problems, but when I tried to copy it to and Samsung Galaxy Gio It said that I dont have permission, is there anyway to solve this without rooting the device or includiong the database in the project? 我尝试将它直接复制到模拟器中的/ data / data / my_project / files7,我没有问题,但是当我试图将它复制到三星Galaxy Gio时它说我没有许可,无论如何要解决这个问题没有生根设备或包含项目中的数据库?

Yes. 是。 You can add any files to your apk file. 您可以将任何文件添加到apk文件中。 To do this just add these strings to project file: 为此,只需将这些字符串添加到项目文件:

deployment.files = cfg.init
deployment.path = /assets/data/data/org.kde.necessitas.example.<package_name>/files
INSTALLS += deployment

There are two restriction: all deployement files are READONLY, and they can be opened only by using AbsolutelyPath. 有两个限制:所有deployement文件都是READONLY,只能使用AbsolutelyPath打开它们。

So, I have solved these problems by adding some code to the program: 所以,我通过向程序添加一些代码解决了这些问题:

if (!QFile::exists("cfg.db"))
{
    QFile dfile("/data/data/org.kde.necessitas.example.<package_name>/files/cfg.init");
    if (dfile.exists())
    {
        dfile.copy("cfg.db");
        QFile::setPermissions("cfg.db",QFile::WriteOwner | QFile::ReadOwner);
    }
}

That's all :) 就这样 :)

我没试过这个,但是如何使用它: Qt资源系统

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM