Results 1 to 6 of 6

Thread: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    I am running two peices of code shown below, both of which are trying to connect to the mysql server (version 5.0.41).

    The codes are shown below; one is basically the carbon copy of the other, they are running on the same machine, same operating system.

    I am using MVS .NET 2003

    The first code (code number one), well thats all there is to it, just a main.cpp file.

    The only difference between the two peices of code is that the last one (code number two), is a part of a large project (and as you can see i have commented the inclusion of other files in the project, in an attempt to get the two peices of code exactly alike).

    I am using QMessageBox to test the outputs and see whats going on.

    From code number one i get a message box telling me that i am connected to the server.

    From code number two i get a message box saying : DRIVER NOT LOADED DRIVER NOT LOADED.

    If you have any suggestions whatsoever that could explain this, please post.

    Thanks in advance for your time.

    Here they are:

    code number one:

    Qt Code:
    1. #include <qapplication.h>
    2. #include<QtCore>
    3. #include<QtGui>
    4. #include <QSqlDatabase>
    5. #include <QSqlError>
    6. #include<QString>
    7.  
    8.  
    9.  
    10.  
    11.  
    12. bool createConnection()
    13. {
    14. QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
    15. db.setHostName("localhost");
    16. db.setDatabaseName("pabxdb");
    17. db.setUserName("root");
    18. db.setPassword("root");
    19. if (!db.open()) {
    20. QMessageBox::critical(0, QObject::tr("Database Error"),
    21. db.lastError().text());
    22. return false;
    23. }
    24. return true;
    25. }
    26.  
    27.  
    28. int main( int argc, char** argv )
    29. {
    30. QApplication app( argc, argv );
    31. const QString stry = "connected";
    32. if(createConnection()){
    33. QMessageBox::information(0, QObject::tr("Database Error"),stry);
    34. } // create database connections
    35.  
    36.  
    37.  
    38. return 0;
    39. }
    To copy to clipboard, switch view to plain text mode 

    code number two

    Qt Code:
    1. #include <QApplication.h>
    2. #include<QtCore>
    3. #include<QtGui>
    4. #include <QSqlDatabase>
    5. #include <QSqlError>
    6. #include<QString>
    7. #include<QStringList>
    8. //#include "global.h"
    9. //#include "mainConsole.h"
    10. //#include "pabxdialog.h"
    11.  
    12.  
    13.  
    14. //bool USER_FLAG; // USER_FLAG GLOBAL VARIABLE ** defined elsewhere as extern **
    15.  
    16.  
    17.  
    18. bool createConnection()
    19. {
    20. QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
    21. db.setHostName("localhost");
    22. db.setDatabaseName("pabxdb");
    23. db.setUserName("root");
    24. db.setPassword("root");
    25. if (!db.open()) {
    26. QMessageBox::critical(0, QObject::tr("Database Error"),
    27. db.lastError().text());
    28. return false;
    29. }
    30. return true;
    31. }
    32.  
    33.  
    34. int main( int argc, char** argv )
    35. {
    36. QApplication app( argc, argv );
    37. const QString stry = "connected";
    38. //const QString stry1 = "driver not found";
    39.  
    40.  
    41.  
    42. if(createConnection()){
    43. QMessageBox::information(0, QObject::tr("Database Error"),stry);
    44. } // create database connections
    45. //mainConsole pabx( 0, 0,0, &app ); // instantiate main console
    46.  
    47.  
    48.  
    49. return 0;
    50. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    Quote Originally Posted by locus View Post
    The only difference between the two peices of code is that the last one (code number two), is a part of a large project
    There must be some other difference that causes the problem. Do you build those two projects in the same way?

  3. #3
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    Thats what i am saying, so i'm trying to find out what the difference is.

    I don't know how relevant these values are to the build, but here are some values that are the same with both projects in the MSVS .NET 2003 environment:

    Project Property Pages:

    Code Generation -> runtime library -> Multithreaded debug Dll (/MDd)

    Linker input -> additional dependencies -> QtSqld4.lib QtCored4.lib ...... (all the libraries here are the same for both projects)

    command line options are also the same.

    i looked through the build log trying to find a difference, there seem to be no significant difference that could explain the problem.

    All qt modules have been included in both projects.


    By adding the piece of code below, to code number two (the one giving the driver not loaded problem, i realize that it is only seeing one driver as available.

    A little bit more code reveils that the only driver it picks up is the QSQLITE.

    Qt Code:
    1. QStringList drivers = QSqlDatabase::drivers();
    2.  
    3. int str_int = drivers.count();
    4.  
    5. QVariant var(str_int);
    6.  
    7. const QString stry3 = var.toString();
    8.  
    9. QMessageBox::information(0, QObject::tr("Database Error"),stry3);
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot for your response, i am still looking.

    The problem is i am running out of differences to look for.

    If there is anything you can suggest please, feel free.

    Thanks again.
    Last edited by locus; 24th June 2007 at 22:54.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    Maybe you should take a look at the contents of directories where the executables are?

  5. The following user says thank you to jacek for this useful post:

    locus (4th July 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    The libmysql.dll with "MySQL 5.0.41" seems not work fine with Qt 4.x.
    I resolved installing MySQL 5.0.37.

    Sorry for my very BAD English
    A camel can go 14 days without drink,
    I can't!!!

  7. #6
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mysterious Qt4.2.0 Mysql 5.0.41 connection problem

    Thanks mcosta for your response.

    I got it to work though.

    Jacek was right, the dll for the sql module was inside my project excecutable directory. Along with some other qt dlls. Can't quite remember why i put them there.

    I think i was trying to get the program to run as a stand alone, ie. by just clicking on the .exe file, without opening the application in visual studio.

    But i remove the dll and everything worked like a charm.

    MCOSTA: The dll works fine, as long as it gets built correctly, if you ever have problems with that you can send me a PM and i'll post you a guide.

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.