Results 1 to 3 of 3

Thread: connect mysql with odbc

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default connect mysql with odbc

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "QtSql"
    4. #include "QLabel"
    5. #include "QMessageBox"
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17. }
    18.  
    19. void MainWindow::on_pushButton_clicked()
    20. {
    21. n->addDatabase("QODBC3","ahm");
    22. n->setHostName("10.0.0.101");
    23. n->setDatabaseName("Driver={MySQL ODBC 5.1.8 Driver};DATABASE=ahm;");
    24. n->setUserName("ahm");
    25. n->setPassword("ahmdtcahm");
    26. n->setPort(3306);
    27.  
    28. /*if (!n->open()) {
    29.  
    30.   QMessageBox::critical(0, QObject::tr("Database Error"),
    31.  
    32.   n->lastError().text());
    33.   }*/
    34. bool cek=n->open();
    35. if(cek==true)
    36. {
    37. QLabel *l=new QLabel();
    38. l->setText("connect");
    39. l->show();
    40. }
    41. else
    42. {
    43. QLabel *l=new QLabel();
    44. l->setText("can't connect");
    45. l->show();
    46.  
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

    and output is can't connect...how can i solve this problem???
    Last edited by high_flyer; 18th April 2011 at 09:37. Reason: code tags

Similar Threads

  1. How to connect Qt with MYSQL??
    By Gokulnathvc in forum Newbie
    Replies: 10
    Last Post: 24th March 2011, 00:52
  2. source code for odbc driver or MySql driver in arm-embedded-linux
    By sattu in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th January 2011, 10:11
  3. Qt connect different MySQL
    By weixj2003ld in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2009, 08:35
  4. How to connect MySQL with QT
    By diego in forum Qt Programming
    Replies: 0
    Last Post: 27th May 2009, 05:34
  5. ODBC Oracle. Unable to connect to database
    By egil in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 13:46

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
  •  
Qt is a trademark of The Qt Company.