Results 1 to 8 of 8

Thread: MySQL database ,Garbled

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default MySQL database ,Garbled

    I create a mysql database in my application,and it is name with Chinese.
    Qt Code:
    1. QString dataBaseDir=mysqlDir+DatabaseName;//DatabaseName(In Chinese)
    2. if(!dir.mkdir(dataBaseDir)){....}
    To copy to clipboard, switch view to plain text mode 
    When I connect the database,I get the following error:Unknown database '????' QMYSQL:Unable to connect.Please help me.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MySQL database ,Garbled

    Quote Originally Posted by weixj2003ld View Post
    Unknown database '????'
    Seems you have a problem with the right text encoding. And your code have nothing to do with a database. Its creating a directory, so could you post the relevant code?

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySQL database ,Garbled

    This is all the codes about creating a mysql database(Because it create a directory in the mysqlInstallDir\Data\).The following code is to connect the database.
    Qt Code:
    1. QSqlDatabase defaultDB = QSqlDatabase::addDatabase( DB_DRIVER );
    2. defaultDB.setDatabaseName( DatabaseName);
    3. defaultDB.setUserName( DB_USER );
    4. defaultDB.setPassword( DB_PASSWD );
    5. defaultDB.setHostName( DB_HOST );
    6. if ( defaultDB.open() )
    7. return true;
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MySQL database ,Garbled

    Fine, and what value has DatabaseName? How do you set the value of that variable and what encoding has your *.cpp file?

  5. #5
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySQL database ,Garbled

    1.the value of DatabaseName is delivered by the GUI,and it is written in Chinese.
    2.Sorry,I don't know how to find the encoding of my *.cpp file.

  6. #6
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: MySQL database ,Garbled

    help me,please.

  7. #7
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MySQL database ,Garbled

    Who can help me?Please.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: MySQL database ,Garbled

    Hi,

    the error is in the encoding, but without any specific informations it is hard to say. So run some tests:

    • create a database with only asci letters as name
    • try to connect via your interface to that database.


    -> If that works, then try different encodings of your QString, when setting the database name for the connection. toLocal8Bit(), utf16()... Try to hardcode, maybe your database does not support database names in utfX

Similar Threads

  1. Problem Wtih Connecting MySQL Database on Windows
    By dummystories in forum Installation and Deployment
    Replies: 25
    Last Post: 29th April 2009, 11:12
  2. Accessing xampp mysql database
    By synack in forum Newbie
    Replies: 8
    Last Post: 19th March 2009, 09:08
  3. Putting and getting images from MySQL database?
    By allensr in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2007, 21:47
  4. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48
  5. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50

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.