簡體   English   中英

使用Qt / C ++確定Google雲端硬盤的位置

[英]Determine Google Drive location with Qt/C++

本質上,這是這里問題的Qt / C ++變體:

如何使用C#以編程方式找到我的Google雲端硬盤文件夾?

我到目前為止已經嘗試了以下

    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();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM