Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 通过setOfflineStoragePath设置本地存储位置_Qt_Sqlite_Qml_Qt5_Qtquick2 - Fatal编程技术网

Qt 通过setOfflineStoragePath设置本地存储位置

Qt 通过setOfflineStoragePath设置本地存储位置,qt,sqlite,qml,qt5,qtquick2,Qt,Sqlite,Qml,Qt5,Qtquick2,我正在尝试为我的QML应用程序设置LocalStorage位置(sqlite db),但一旦我重建并运行应用程序,我仍然无法看到在所需位置(在资源文件夹的子文件夹中)创建的子文件夹、INI文件和sqlite db。这是我的主文件中的内容。 感谢任何人能品脱我做错了什么 #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include <Q

我正在尝试为我的QML应用程序设置
LocalStorage
位置(sqlite db),但一旦我重建并运行应用程序,我仍然无法看到在所需位置(在资源文件夹的子文件夹中)创建的子文件夹、INI文件和sqlite db。这是我的主文件中的内容。
感谢任何人能品脱我做错了什么

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QString>
#include <QDebug>
#include <QDir>

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

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    //engine.setOfflineStoragePath("qrc:/");
    auto offlineStoragePath = QUrl::fromLocalFile(engine.offlineStoragePath());
    engine.rootContext()->setContextProperty("offlineStoragePath", offlineStoragePath);

    QString customPath = "qrc:/OffLineStorage";

    QDir dir;
    if(dir.mkpath(QString(customPath))){
        qDebug() << "Default path >> "+engine.offlineStoragePath();
        engine.setOfflineStoragePath(QString(customPath));
        qDebug() << "New path >> "+engine.offlineStoragePath();
    }


    return app.exec();
}
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
QGUI应用程序应用程序(argc、argv);
qqmlaplicationengine;
engine.load(QUrl(QStringLiteral(“qrc:/main.qml”));
//engine.setOfflineStoragePath(“qrc:/”);
auto offlineStoragePath=QUrl::fromLocalFile(engine.offlineStoragePath());
engine.rootContext()->setContextProperty(“offlineStoragePath”,offlineStoragePath);
QString customPath=“qrc:/OffLineStorage”;
QDir-dir;
if(dir.mkpath(QString(customPath))){

qDebug()通过查看问题中的代码片段,一切看起来都很好。
无论如何,您应该验证以下行是否实际返回预期的
true

dir.mkpath(QString(customPath)
如果否,则在任何情况下都不会执行
If
语句的主体,因此永远不会调用
setOfflineStoragePath


作为提示,使用
qrc:/OffLineStorage
作为存储路径似乎不是一个好主意。我不确定它在生产环境中是否能工作一次(需要检查,这听起来很奇怪,但它可以工作)。

通过查看您问题中的代码片段,一切看起来都很好。
无论如何,您应该验证以下行是否实际返回预期的
true

dir.mkpath(QString(customPath)
如果否,则在任何情况下都不会执行
If
语句的主体,因此永远不会调用
setOfflineStoragePath


作为提示,使用
qrc:/OffLineStorage
作为存储路径似乎不是一个好主意。我不确定它在生产环境中是否能工作一次(需要检查,这听起来很奇怪,但它可以工作)。

尝试在
引擎.load
之前使用
引擎.setOfflineStoragePath

使用qrc:/OffLineStorage作为存储路径似乎不太合适 这是个好主意。我不确定它在生产过程中是否会起作用 环境

#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
QGUI应用程序应用程序(argc、argv);
qqmlaplicationengine;
QString customPath=“qrc:/OffLineStorage”;
QDir-dir;
if(dir.mkpath(QString(customPath))){

qDebug()在
引擎加载之前尝试使用
引擎.setOfflineStoragePath

使用qrc:/OffLineStorage作为存储路径似乎不太合适 这是个好主意。我不确定它在生产过程中是否会起作用 环境

#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
QGUI应用程序应用程序(argc、argv);
qqmlaplicationengine;
QString customPath=“qrc:/OffLineStorage”;
QDir-dir;
if(dir.mkpath(QString(customPath))){

qDebug()您是否检查了
mkpath
是否确实创建了所需的路径?我的意思是,很可能是
if
语句的主体从未执行过。@skypjack刚刚检查了skypjack,文件夹没有创建。我将手动创建它,并在之前提供。谢谢查看。不客气。我将在几分钟,以便接受它并根据需要关闭问题。您是否检查了
mkpath
是否确实创建了所需的路径?我的意思是,很可能是
if
语句的主体从未执行过。@skypjack刚刚检查了skypjack,文件夹没有创建。我将手动创建它并在以前提供。谢谢在这方面。不客气。我将在几分钟后添加评论作为回复,以便接受它并关闭问题(如果您愿意)。尝试手动创建文件夹并运行,但仍然没有成功。我认为它受到设计的限制。恢复使用默认位置:)谢谢您查看此内容。我通常使用默认位置阳离子,但一旦我也给了用户选择所需位置的机会。无论如何,默认位置在大多数情况下都是一个很好的选择。;-)尝试手动创建文件夹并运行,但仍然没有成功。我认为它受到设计的限制。恢复使用默认位置:)谢谢你看到了这一点。我告诉我们通常使用默认位置,但一旦我也给了用户选择所需位置的机会。无论如何,默认位置在大多数情况下都是一个不错的选择。;-)