Results 1 to 2 of 2

Thread: Database not being created

  1. #1
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Database not being created

    Hi all I have been trying for hours now to get a MySQL database to work in my project. Only problem is I am unable to create the database. I don't get any errors anything, nothing seems to happen. Everything compiles fine but no databases are created. Qt tells me that I have all the database drivers i need...

    I have: ("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC")

    The code that I'm using to try and create my database is:

    Qt Code:
    1. db.addDatabase("QMYSQL");
    2. db.setDatabaseName("test");
    3. if(!db.open()){
    4. message.information(this, "Error", "Database not opened");
    5. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong? This is all beginning to annoy me now!!

    Thanks for your time and trouble. Any help would be much appreciated

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Database not being created

    Two things:
    1. You need to provide the Mysql plugin with a host name, user name, and password. From the docs:
      Qt Code:
      1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      2. db.setHostName("bigblue");
      3. db.setDatabaseName("flightdb");
      4. db.setUserName("acarlson");
      5. db.setPassword("1uTbSbAs");
      6. bool ok = db.open();
      To copy to clipboard, switch view to plain text mode 
    2. The plugin will not create the Mysql database if it does not exist.

Similar Threads

  1. Replies: 9
    Last Post: 20th May 2010, 09:55
  2. Check has created with new
    By wirasto in forum Qt Programming
    Replies: 5
    Last Post: 16th March 2010, 16:02
  3. GUI created from Database
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 3rd February 2009, 00:43
  4. MSVC no .lib created
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 13th February 2008, 12:32
  5. Line not being created
    By Kapil in forum Newbie
    Replies: 4
    Last Post: 30th March 2006, 06:49

Tags for this Thread

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.