c++ - 使用 Qt/C++ 确定 Google Drive 位置

标签 c++ qt google-drive-api

本质上这是这里问题的 Qt/C++ 变体:

How do I programmatically locate my Google Drive folder using C#?

到目前为止我尝试过的内容如下所示

    QString gDrivePath =  QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    gDrivePath += "\\Google\\Drive\\sync_config.db";
    bool result = QFile::copy(gDrivePath, "gdrive.db");

    QFile gdrivefile("gdrive.db");
    if(!gdrivefile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QMessageBox::information(0, "Google Drive path read error", gdrivefile.errorString());
    }

    QTextStream gin(&gdrivefile);
    gin.setCodec("ASCII");
    while(!gin.atEnd()) {
        qDebug() << gin.readLine().toLocal8Bit();
    }
    gdrivefile.close();

就像上面链接的问题中给出的那样,代码复制了 db 文件并尝试逐行读取它。唯一的问题是它从包含所需“local_sync_root_pathvalue”的文件中跳过了一大块数据

有什么想法吗?

最佳答案

我最终使用 qt 中的 sql 类来实现这一壮举。

代码:

    QString gDrivePath =  QDesktopServices::storageLocation(QDesktopServices::DataLocation);
    gDrivePath += "\\Google\\Drive\\sync_config.db";
    QFile::copy(gDrivePath, "gdrive.db");

    QFile gDriveFile("gdrive.db");
    if(!gDriveFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Error in opening Google Drive File" << gDriveFile.errorString();
    }
    else {
        QSqlDatabase gDrivedb = QSqlDatabase::addDatabase("QSQLITE");
        gDrivedb.setDatabaseName("gdrive.db");
        if (gDrivedb.open()) {
            QSqlQuery query(gDrivedb);
            if (query.exec("select * from data where entry_key='local_sync_root_path'")) {
                 while (query.next()) {
                     QString gDrivePath = query.value(2).toString().remove(0,4);
                     qDebug() << "Google Drive at - " << gDrivePath;
                 }
            } else {
                qDebug() << "Error in querying Google Drive db" << query.lastError();
            }
        }
        else
            qDebug() << "Error in Opening  Google Drive db";
        gDriveFile.close();
    }

关于c++ - 使用 Qt/C++ 确定 Google Drive 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18649631/

相关文章:

c++ - 访问 zip 文件中文件的最快方法是什么?

c++ - 无法使用 QtCreator #include <QWebView>

c++ - 使用来自 Qt 的 symbian native API

c++ - 使用 QtUdpSocket 的简单通信 c/s 应用程序

c++ - 常量的隐式转换

c++ - 为什么在下面的代码中调用了第一个复制构造函数?

javascript - 将图像从 Google Drive 加载到 HTML Canvas 会导致 Canvas 被污染

python - malloc() : unsorted double linked list corrupted Aborted (core dumped) python

c++ - 如何在 QGraphicsScene 上绘制一个点(通过鼠标单击)?

javascript - 使用 javascript 将任何人的文件上传到我的谷歌驱动器