Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Ressource file not found in Linux but works in Windows
Forum Updated to NodeBB v4.3 + New Features

Ressource file not found in Linux but works in Windows

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nayar
    wrote on last edited by
    #1

    Hi, I am using a QRessource to fetch an SQL to run. However it is getting the file in windows only.

    @QFile createTableSQLFile(":/sql/dbinstaller.sql");@

    Here's my meradatabase.h
    @class MeraDatabase
    {
    public:
    static QSqlQuery exec(QString sql);
    static QSqlDatabase getDB();

    protected:
    static QSqlDatabase init();
    private:
    static const QSqlDatabase db;
    static bool install(QSqlDatabase temp);
    };@

    meradatabase.cpp

    @#include "meradatabase.h"
    #include <QtSql>
    #include "iostream"
    #include "string"
    #include <fstream>
    #include <QtDebug>
    #include <QSqlDatabase>

    using namespace std;

    const QSqlDatabase MeraDatabase::db = MeraDatabase::init();

    bool MeraDatabase::install(QSqlDatabase temp)
    {
    temp.open();
    qDebug() << "Installing..";

    //installlock.open(QIODevice::WriteOnly | QIODevice::Text);
    //QTextStream out(&installlock);
    //out << "locked";
    QString sql;
    
    
    QFile createTableSQLFile&#40;":/sql/dbinstaller.sql"&#41;;
    if(createTableSQLFile.open(QIODevice::ReadOnly&#41;&#41;{ // This is failing in Linux <<<<<<<<<<<<<<<<<<<
        
        //temp.exec&#40;"CREATE DATABASE fuzzycompostdb"&#41;;
        sql = createTableSQLFile.readAll(&#41;;
        temp.exec(sql&#41;;
        qDebug(&#41; << ".. Creating tables..";
        qDebug(&#41; << temp.lastError();
    
        QFile addDefaultSubstrates(":/sql/defaultsubstrates.sql");
        if(addDefaultSubstrates.open(QIODevice::ReadOnly)){
            sql = addDefaultSubstrates.readAll();
            temp.exec&#40;sql&#41;;
            qDebug(&#41; << ".. Adding Default Values.." <<sql;
            qDebug(&#41; << temp.lastError();
        }
    }
    
    return true;
    

    }

    QSqlDatabase MeraDatabase::init()
    {
    qDebug() << "Getting DB connection";
    QString dbName = "fuzzyDB";
    QString dbType = "QSQLITE";
    //QSqlDatabase db;
    QSqlDatabase temp;
    if(dbType == "QSQLITE"){
    temp = QSqlDatabase::addDatabase("QSQLITE");
    qDebug() << "sqlite temp..";
    //temp.addDatabase("QSQLITE");
    temp.setDatabaseName(dbName + "db3");
    QFile installlock("installlock");
    if(!installlock.exists()){
    install(temp);
    }
    }

    QSqlQuery result = temp.exec&#40;"select * from substrate_type"&#41;;
    qDebug(&#41; << temp.lastError(&#41;;
    qDebug() << "name";
    while(result.next()){
        qDebug() << "name" <<result.value("name");
    }
    return temp;
    

    }

    QSqlQuery MeraDatabase::exec(QString sql)
    {
    return db.exec(sql);
    }@

    If i use the resource outside this class, it works fine on both Linux and windows. Dunno why my Linux Qt can't find the file.

    Best Regards
    Nayar

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Make sure all the paths are correct. Windows uses different build directories by default, it can cause a lot of hard-to-debug bugs.

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jmimi
        wrote on last edited by
        #3

        Please give your .pro file.
        The only reason is that resources does not be packed in your build.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nayar
          wrote on last edited by
          #4

          Managed to get it to work. I put @ Q_INIT_RESOURCE(fcl);@ before using the files and it worked.

          Dunno why on linux and in static functions, Q_QINIT is required but works "out of the box" on Windows

          Thanks guys :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved