Page 2 of 2 FirstFirst 12
Results 21 to 40 of 40

Thread: MySQL Driver not loaded on PC without Qt

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Quote Originally Posted by KTvsPeacock View Post
    The problem is that my Application only searches in that path, no matter what, for plugins.
    How do you know it doesn't search elsewhere?

    I could add thousand additional paths and put the needed dll in every single one of them, but only the one lies in the qt/plugins-path will be used.
    And this is not that good, if I want to use my application on a PC without Qt :/
    Apparently you are missing some library that is required by the driver. Run dependency walker on the plugin and see if anything is missing and what is required for it to work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #22
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    It was just a guess, because by removing every library path the application will still look in qt/plugins/sqldrivers.

    I used Dependency Walker on App/sqldrivers/qsqlmysql4.dll:
    QtCore4.dll and QtSql4.dll were missing, but they were in the /App-folder, so I copied them also into that folder.
    -> Available Drivers: ("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC") , but still QSqlError(-1, "Driver not loaded", "Driver not loaded")

    Dependencies on qsqlmysql4.dll:
    LIBMYSQL.DLL
    KERNEL32.DLL
    MINGWM10.DLL
    MSVCRT.DLL
    LIBGCC_S_DW2-1.DLL
    QTCORE4.DLL
    QTSQL4.DLL

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Obviously your driver is seen by the application. Show us your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #24
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    I tried to pick the important ones:

    main.cpp:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QObject>
    3. #include <QDebug>
    4. #include "dialog.h"
    5. #include "mainwindow.h"
    6. #include "datenbank.h"
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. qDebug()<<"["<<(Datenbank::iMethodenZaehler++)<<"]"<<"enter main";
    11. QApplication a(argc, argv);
    12. Dialog *d = new Dialog;
    13. MainWindow *w = new MainWindow;
    14. QObject::connect(d,SIGNAL(signalUser(QString)),w,SLOT(slotUser(QString)));
    15. if(d->exec()){
    16. w->show();
    17. }else{
    18. delete w;
    19. delete d;
    20. return 1;
    21. }
    22. delete d;
    23. int i = a.exec();
    24. qDebug()<<"["<<(--Datenbank::iMethodenZaehler)<<"]"<<"exit main";
    25. return i;
    26. }
    To copy to clipboard, switch view to plain text mode 

    datenbank.cpp:
    (every method in the datenbank class is static)
    Qt Code:
    1. #include "datenbank.h"
    2.  
    3. QSqlDatabase Datenbank::myDB = QSqlDatabase::addDatabase("QMYSQL");
    4.  
    5. bool Datenbank::initDB(QString qsDB,QString qsHost,QString qsNutzer, QString qsKW, int iPort, DB_MODES mode){
    6. myDB.setDatabaseName(qsDB);
    7. myDB.setHostName(qsHost);
    8. myDB.setUserName(qsNutzer);
    9. myDB.setPassword(qsKW);
    10. myDB.setPort(iPort);
    11. qDebug()<<myDB.drivers();
    12. bool b = false;
    13. checkOpenConnection(mode);
    14. if(myDB.isOpen()){
    15. b=true;
    16. checkCloseConnection(mode);
    17. }else{
    18. qDebug()<<myDB.lastError();
    19. }
    20. return b;
    21. }
    To copy to clipboard, switch view to plain text mode 

    includes in datenbank.h:
    Qt Code:
    1. #include <QSqlDatabase>
    2. #include <QSqlQuery>
    3. #include <QSqlError>
    4. #include <QStringList>
    5. #include <QVariant>
    6. #include <QDebug>
    7. #include <QDateTime>
    To copy to clipboard, switch view to plain text mode 

    Hope this helps.

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Here we are...

    Your addDatabase() call is made as an initialization of a static variable which places it before the execution of main(). Now in main() the QApplication object is being initialized and during its initialization it loads plugins. Therefore you are trying to add a database before any plugins are actually loaded. This can't work regardless of whether Qt is preinstalled on a particular machine or not.

    Now to fix it all... QSqlDatabase::addDatabase() and QSqlDatabase::database() are static calls. The point is you don't have to assign their return values to any persistent variables because you can always retrieve the connection later. You can also simply move the initialization of the database object to main() or any other place after QApplication is already created.

    When talking about main(), you can simplify it to:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. qDebug()<<"["<<(Datenbank::iMethodenZaehler++)<<"]"<<"enter main";
    4. QApplication a(argc, argv);
    5. Dialog d;
    6. MainWindow w;
    7. QObject::connect(&d,SIGNAL(signalUser(QString)),&w,SLOT(slotUser(QString)));
    8. if(d.exec()){
    9. w.show();
    10. }else{
    11. return 1;
    12. }
    13. int i = a.exec();
    14. qDebug()<<"["<<(--Datenbank::iMethodenZaehler)<<"]"<<"exit main";
    15. return i;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Also have a look at this snippet regarding debugging:
    http://blog.wysota.eu.org/index.php/...ugging-helper/
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #26
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    Strange, BUT addDatabase() does work, if qsqlmysql4.dll lies in qt/plugins/sqldrivers :/

    Finally I could solve this mistery with your help.
    I added Datenbank::myDB.addDataBase("myConnection") to my main.cpp return the connection to myDB in the initDB-method using myDB = QSqlDatabase::database("myConnection");

    Now I have to write an e-mail to my teacher, which taught me to define a database connection this way

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Quote Originally Posted by KTvsPeacock View Post
    Strange, BUT addDatabase() does work, if qsqlmysql4.dll lies in qt/plugins/sqldrivers :/
    I don't think it is possible. Maybe you didn't rebuild some code or you have a static compilation of your application or something like that. addDatabase() cannot work before Q(Core)Application is constructed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    It worked like this in many other applications of me and about 60 other people I know
    Maybe it's an error of Qt.

  9. #29
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Quote Originally Posted by KTvsPeacock View Post
    It worked like this in many other applications of me and about 60 other people I know
    Maybe it's an error of Qt.
    It would rather be a miracle (or a badly written compiler) as I can assure you plugins are not loaded before QApplication constructor is executed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #30
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    You can try it on your own, if you want to.
    Just:
    - download the Qt SDK from the website
    - install MySQL
    - use the generic settings
    - write a class like my datenbank.h/cpp
    - compile

    Like I said: I was told by my teacher to use QSqlDatabase this way and it worked for me and each other pupil of him in the last 3 years

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    This crashes on me immediately (on Linux):
    Qt Code:
    1. #include <QtCore>
    2. #include <QtSql>
    3.  
    4. class DBClass {
    5.  
    6. private:
    7. static QSqlDatabase db;
    8. };
    9.  
    10. QSqlDatabase DBClass::db = QSqlDatabase::addDatabase("QSQLITE");
    11.  
    12. int main(int argc, char **argv){
    13. QCoreApplication app(argc, argv);
    14. return 0;
    15. };
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    This setting "worked" for me:
    database.pro:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = database
    4. TEMPLATE = app
    5.  
    6.  
    7. SOURCES += main.cpp\
    8. datenbank.cpp
    9.  
    10. HEADERS += \
    11. datenbank.h
    12.  
    13. QT += sql
    To copy to clipboard, switch view to plain text mode 

    datenbank.h:
    Qt Code:
    1. #ifndef DATENBANK_H
    2. #define DATENBANK_H
    3.  
    4. #include <QSqlDatabase>
    5. #include <QSqlQuery>
    6. #include <QSqlError>
    7. #include <QStringList>
    8. #include <QVariant>
    9. #include <QDebug>
    10.  
    11. class Datenbank
    12. {
    13.  
    14. public:
    15. static QSqlDatabase myDB;
    16. Datenbank();
    17. };
    18.  
    19. #endif // DATENBANK_H
    To copy to clipboard, switch view to plain text mode 

    datenbank.cpp:
    Qt Code:
    1. #include "datenbank.h"
    2.  
    3. QSqlDatabase Datenbank::myDB = QSqlDatabase::addDatabase("QMYSQL"); //works also with QSQLITE
    4.  
    5. Datenbank::Datenbank()
    6. {
    7. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "datenbank.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. qDebug()<<Datenbank::myDB;
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Using QCoreApplication won't do the trick.

  13. #33
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    What if you move the qDebug() statement before the application constructor?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #34
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    Still works, but only with QApplication.
    QCoreApplication doesn't like it that way

  15. #35
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    What if you remove the application object completly and just leave the debug statement?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #36
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    It works even without QApplication, but it has to be included.
    Else I wont get any message.

  17. #37
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    And what message do you get?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #38
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    If I added the setUser, etc.-methods and now I'm able to open a database.
    QSqlDatabase(driver=""QMYSQL"", database=""notenuebersicht_10_11"", host=""192.168.0.112"", port=3306, user=""gast"", open=true)

    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include "datenbank.h"
    3.  
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. Datenbank::initDB();
    8. qDebug()<<Datenbank::myDB;
    9. }
    To copy to clipboard, switch view to plain text mode 

    datenbank.h:
    Qt Code:
    1. #ifndef DATENBANK_H
    2. #define DATENBANK_H
    3.  
    4. #include <QSqlDatabase>
    5. #include <QDebug>
    6.  
    7. class Datenbank
    8. {
    9.  
    10. public:
    11. static QSqlDatabase myDB;
    12. Datenbank();
    13. static void initDB();
    14. };
    15.  
    16. #endif // DATENBANK_H
    To copy to clipboard, switch view to plain text mode 

    datenbank.cpp:
    Qt Code:
    1. #include "datenbank.h"
    2.  
    3. QSqlDatabase Datenbank::myDB = QSqlDatabase::addDatabase("QMYSQL");
    4.  
    5. Datenbank::Datenbank()
    6. {
    7. }
    8.  
    9. void Datenbank::initDB(){
    10. myDB.setHostName("192.168.0.112");
    11. myDB.setDatabaseName("notenuebersicht_10_11");
    12. myDB.setUserName("gast");
    13. myDB.setPassword("gast");
    14. myDB.setPort(3306);
    15. myDB.open();
    16. }
    To copy to clipboard, switch view to plain text mode 

  19. #39
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MySQL Driver not loaded on PC without Qt

    Could you please check what QCoreApplication::startingUp() returns?

    I just started thinking... maybe they changed QSqlDatabase::addDatabase() to load plugins if they are not loaded? I'll have a look at the source code...

    Edit: No, they didn't...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #40
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Driver not loaded on PC without Qt

    startingUp() returns true.

Similar Threads

  1. mysql driver not loaded after deployment
    By tpf80 in forum Newbie
    Replies: 4
    Last Post: 4th September 2011, 10:12
  2. MySQL driver , I have, it still not loaded
    By bigkoma in forum Qt Programming
    Replies: 14
    Last Post: 30th January 2011, 10:38
  3. Sql Driver: MYSQL not loaded
    By stilgar in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2010, 10:35
  4. MySQL driver not loaded
    By hami in forum Installation and Deployment
    Replies: 1
    Last Post: 12th May 2009, 19:54
  5. MySql Driver not loaded
    By eekhoorn12 in forum Installation and Deployment
    Replies: 13
    Last Post: 18th June 2007, 13:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.