Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. QODBC su Linux Ubuntu 17.04
Qt 6.11 is out! See what's new in the release blog

QODBC su Linux Ubuntu 17.04

Scheduled Pinned Locked Moved Solved Italian
7 Posts 3 Posters 3.5k 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.
  • B Offline
    B Offline
    Bruschetta
    wrote on last edited by Bruschetta
    #1

    Ho disperatamente bisogno di un consiglio..
    Sto cercando (invano) di far funzionare l'applicazione che ho sviluppato su windows su un sistema linux. A dire il vero va tutto tranne la comunicazione con il DB. Sfortunatamente il DB è un maledettissimo file Access e quindi necessito dei drivers ODBC.

    Ho seguito questa guida http://doc.qt.io/qt-5/sql-driver.html ed ho installato i drivers unixODBC (il comando odbc_config --version mi ritorna 2.3.4) e poi sono andato per compilare il tutto con il qmake.

    Mi sono messo quindi nella directory ~/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc ed ho lanciato il comando

    sudo '/home/rusty/Qt/5.9.1/gcc_64/bin/qmake' "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lodbc" odbc.pro
    

    Il comando mi ha ritornato questo errore

     Project ERROR: Library 'odbc' is not defined.
    

    Non so che cosa sbaglio.. Ho guardato diverse guide ma i passaggi sembrano questi.. Qualche hint?

    PS la connection open nel software la faccio così:

     bool connectionOpen(){
               QSqlDatabase db = QSqlDatabase::database("Contact");
               if (db.isOpen()) {
                   return true;
               }else{
                   static QString path = PATH;
                   path = QDir::toNativeSeparators(path);
                   mydb = QSqlDatabase::addDatabase("QODBC", "Contact");
                   QString params="Driver={Microsoft Access Driver (*.mdb)};FIL={Access};DBQ="+ path;
                   mydb.setDatabaseName(params);
    
                   if (!mydb.open())
                   {
                       qDebug() << "Error: connection with database fail";
                       qDebug() << mydb.lastError().text();
                       return false;
                   }
                   else
                   {
                       qDebug() << "Database: connection ok";
                       return true;
                   }
                   return true;
               }
           }
    
    

    E l'app mi da questo errore

    QSqlDatabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    
    Error: connection with database fail
    "Driver not loaded Driver not loaded"
    
    1 Reply Last reply
    0
    • F Offline
      F Offline
      fermatqt
      wrote on last edited by
      #2

      ciao!

      forse non c'entra nulla, ma hai aggiunto sql nel tuo file .pro??

      QT       += core gui sql
      

      a me è bastato questo (oltre ad installlare unixODBC ovviamente).
      quel comando che hai dato tu, non l'ho mai usato....

      B 1 Reply Last reply
      0
      • F fermatqt

        ciao!

        forse non c'entra nulla, ma hai aggiunto sql nel tuo file .pro??

        QT       += core gui sql
        

        a me è bastato questo (oltre ad installlare unixODBC ovviamente).
        quel comando che hai dato tu, non l'ho mai usato....

        B Offline
        B Offline
        Bruschetta
        wrote on last edited by
        #3

        @fermatqt
        Grazie per la risposta però si ho anche quello :(

        QT       += core gui sql printsupport network svg
        
        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by hskoglund
          #4

          Hi, don't speak Italian but nevertheless I think you've been bitten by this bug

          The workaround is to edit the .pro file: ~/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc/odbc.pro:

          TARGET = qsqlodbc
          
          HEADERS += $$PWD/qsql_odbc_p.h
          SOURCES += $$PWD/qsql_odbc.cpp $$PWD/main.cpp
          
          # QMAKE_USE += odbc  ### comment out this line
          unix: DEFINES += UNICODE
          
          OTHER_FILES += odbc.json
          
          PLUGIN_CLASS_NAME = QODBCDriverPlugin
          include(../qsqldriverbase.pri)
          

          and try this command:

          sudo '/home/rusty/Qt/5.9.1/gcc_64/bin/qmake' "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lodbc"
          

          Note: no odbc.pro at the end of the command.

          B 1 Reply Last reply
          2
          • hskoglundH hskoglund

            Hi, don't speak Italian but nevertheless I think you've been bitten by this bug

            The workaround is to edit the .pro file: ~/Qt/5.9.1/Src/qtbase/src/plugins/sqldrivers/odbc/odbc.pro:

            TARGET = qsqlodbc
            
            HEADERS += $$PWD/qsql_odbc_p.h
            SOURCES += $$PWD/qsql_odbc.cpp $$PWD/main.cpp
            
            # QMAKE_USE += odbc  ### comment out this line
            unix: DEFINES += UNICODE
            
            OTHER_FILES += odbc.json
            
            PLUGIN_CLASS_NAME = QODBCDriverPlugin
            include(../qsqldriverbase.pri)
            

            and try this command:

            sudo '/home/rusty/Qt/5.9.1/gcc_64/bin/qmake' "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lodbc"
            

            Note: no odbc.pro at the end of the command.

            B Offline
            B Offline
            Bruschetta
            wrote on last edited by Bruschetta
            #5

            @hskoglund you have been very kind to answer a question that you cannot fully understand.
            I followed the steps you told me and i got no error this time. :)

            Anyway my application is still having problem while i try to connect to the DB.
            The error is still the same :

            QSqlDatabase: QODBC driver not loaded
            QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
            Error: connection with database fail
            "Driver not loaded Driver not loaded"
            

            Do you think there are some passages i have skipped? Thank you for your time
            !

            This is the error i got after make is launched

            rm -f libqsqlodbc.so
            g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,\$ORIGIN/../../lib -Wl,-rpath,\$ORIGIN/../../lib -shared -o libqsqlodbc.so .obj/qsql_odbc.o .obj/main.o .obj/moc_qsql_odbc_p.o  -L/usr/local/lib -lodbc -L/home/rusty/Qt/5.9.1/Src/qtbase/lib -lQt5Sql -lQt5Core -lpthread  
            /usr/bin/ld: saltato /home/rusty/Qt/5.9.1/Src/qtbase/lib/libQt5Sql.so incompatibile durante la ricerca di -lQt5Sql
            /usr/bin/ld: impossibile trovare -lQt5Sql
            /usr/bin/ld: saltato /home/rusty/Qt/5.9.1/Src/qtbase/lib/libQt5Core.so incompatibile durante la ricerca di -lQt5Core
            /usr/bin/ld: impossibile trovare -lQt5Core
            collect2: error: ld returned 1 exit status
            Makefile:73: set di istruzioni per l'obiettivo "/home/rusty/Qt/5.9.1/Src/qtbase/plugins/sqldrivers/libqsqlodbc.so" non riuscito
            make: *** [/home/rusty/Qt/5.9.1/Src/qtbase/plugins/sqldrivers/libqsqlodbc.so] Errore 1
            
            
            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by
              #6

              Hi, it looks almost ok except for .... -L/home/rusty/Qt/5.9.1/Src/qtbase/lib... on the g++ command line. That's why ld cannot find libQt5Sql.so etc.
              For it to work, it should be ...-L/home/rusty/Qt/5.9.1/gcc_64/lib...

              Perhaps the qmake command took a wrong turn somewhere :-)
              Anyway, what you can do, is edit the Makefile that qmake created, it should be in your odbc directory, look for the line starting with LIBS, it should look like this:

              LIBS       = $(SUBLIBS) -L/usr/local/lib -lodbc -L/home/rusty/Qt/5.9.1/gcc_64/lib -lQt5Sql -lQt5Core -lpthread
              

              If if does not, try changing it. Then touch a .cpp file, .e.g. touch qsql_odbc.cpp and try make again.

              B 1 Reply Last reply
              1
              • hskoglundH hskoglund

                Hi, it looks almost ok except for .... -L/home/rusty/Qt/5.9.1/Src/qtbase/lib... on the g++ command line. That's why ld cannot find libQt5Sql.so etc.
                For it to work, it should be ...-L/home/rusty/Qt/5.9.1/gcc_64/lib...

                Perhaps the qmake command took a wrong turn somewhere :-)
                Anyway, what you can do, is edit the Makefile that qmake created, it should be in your odbc directory, look for the line starting with LIBS, it should look like this:

                LIBS       = $(SUBLIBS) -L/usr/local/lib -lodbc -L/home/rusty/Qt/5.9.1/gcc_64/lib -lQt5Sql -lQt5Core -lpthread
                

                If if does not, try changing it. Then touch a .cpp file, .e.g. touch qsql_odbc.cpp and try make again.

                B Offline
                B Offline
                Bruschetta
                wrote on last edited by
                #7

                @hskoglund you were right, i make the modification you told me to do and now i have my ODBC3 driver installed. Now i have some problem while connecting with the DB but ,at least, is not a driver problem!

                Thank you!

                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