Results 1 to 3 of 3

Thread: Problems compiling a QT application for connecting with a remote mysql database

  1. #1
    Join Date
    Apr 2010
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded

    Unhappy Problems compiling a QT application for connecting with a remote mysql database

    Hello I am working with the Qt code of mythv-0.22 source code in a MythUbuntu distro in Ubuntu 9.10.
    I am trying to modify the Qt code of mythv-022 for connecting to a remote database and obatining some data. I have used the Qt Developer and tried to modify the main.cpp class.
    I make the following changes :

    The main.h file has not been modified. I include the following .h files in the main.cpp project:

    #include "qapplication.h"
    #include "qsqldatabase.h"
    #include "qsqlerror.h"
    #include "qlabel.h"

    In main.cpp I have writen the following code , which is supposed to be used for connecting to the Mysql Database:

    void conection_server(void){
    QSqlDatabase * conexion = QSqlDatabase::addDatabase("QMYSQL3");
    conexion->setDatabaseName("mysql");
    conexion->setUserName("root");
    conexion->sethostName("152.168.54.5");
    }

    I compile and obtain the following mistake

    "main.cpp:1107: error: cannot convert ´QSqlDatabase´ to ´QSqlDatabase´ in initialization"

    The line 1107 is the following :

    QSqlDatabase * conexion = QSqlDatabase::addDatabase("QMYSQL3");

    Does anybody know how to solve this compilation mistake ?


    Thanks ,Gorka

  2. #2
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Problems compiling a QT application for connecting with a remote mysql database


  3. #3
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems compiling a QT application for connecting with a remote mysql database

    QSqlDatabase::addDatabase return object of class QSqlDatabase, but not pointer to it
    do this:
    Qt Code:
    1. QSqlDatabase connection = QSqlDatabase::addDatabase( ...
    To copy to clipboard, switch view to plain text mode 

    by the way, you shouldn't declare QSqlDatabase connection inside your function void conection_server(void), because it will destroyed when function will return.

Similar Threads

  1. Replies: 3
    Last Post: 9th February 2011, 20:30
  2. Problem Wtih Connecting MySQL Database on Windows
    By dummystories in forum Installation and Deployment
    Replies: 25
    Last Post: 29th April 2009, 11:12
  3. Problem connecting to remote database
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 16th April 2009, 10:59
  4. Connecting to my database
    By miguel_mark in forum Qt Programming
    Replies: 6
    Last Post: 22nd October 2007, 09:50
  5. Acces to a remote mysql server
    By Alienxs in forum Qt Programming
    Replies: 2
    Last Post: 19th August 2006, 03:10

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.