Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. About QMYSQL. No Error but also No Connection. Raspberry Pi 3 . QT

About QMYSQL. No Error but also No Connection. Raspberry Pi 3 . QT

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
3 Posts 3 Posters 957 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gorkemhacioglu
    wrote on last edited by gorkemhacioglu
    #1

    Hello everyone. I am newbie in QT. I have a problem. My compiler doesn't give me an error but i can not connect my MYSQL database. Please help, here is my code.

    #include "widget.h"
    #include "ui_widget.h"
    #include <QtGui>
    #include <QKeyEvent>
    #include <QThread>
    #include <qtextstream.h>
    #include <QProcess>
    #include <QString>
    #include<QtSql/QSqlDatabase>
    #include<QtSql/QSqlQuery>
    #include <QtSql/qsql.h>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlDriver>
    #include <QtSql/QSqlQuery>
    #include <QSqlTableModel>
    #include <QtSql/QSqlError>
    
    using namespace std;
    
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
    
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("raspidb");
        db.setUserName("root");
        db.setPassword("pass1234");
        db.setPort(3306);
        if(!db.open())
           ui->label->setText("not connected");
    
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    
    
    

    and my .pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = untitled6
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            widget.cpp
    
    HEADERS  += widget.h
    
    FORMS    += widget.ui
    INCLUDEPATH += /usr/include/c++/4.3
    QT += sql
    
    
    GuapoG jsulmJ 2 Replies Last reply
    0
    • G gorkemhacioglu

      Hello everyone. I am newbie in QT. I have a problem. My compiler doesn't give me an error but i can not connect my MYSQL database. Please help, here is my code.

      #include "widget.h"
      #include "ui_widget.h"
      #include <QtGui>
      #include <QKeyEvent>
      #include <QThread>
      #include <qtextstream.h>
      #include <QProcess>
      #include <QString>
      #include<QtSql/QSqlDatabase>
      #include<QtSql/QSqlQuery>
      #include <QtSql/qsql.h>
      #include <QtSql/QSqlDatabase>
      #include <QtSql/QSqlDriver>
      #include <QtSql/QSqlQuery>
      #include <QSqlTableModel>
      #include <QtSql/QSqlError>
      
      using namespace std;
      
      Widget::Widget(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Widget)
      {
          ui->setupUi(this);
      
      
          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("localhost");
          db.setDatabaseName("raspidb");
          db.setUserName("root");
          db.setPassword("pass1234");
          db.setPort(3306);
          if(!db.open())
             ui->label->setText("not connected");
      
      }
      
      Widget::~Widget()
      {
          delete ui;
      }
      
      
      
      

      and my .pro

      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = untitled6
      TEMPLATE = app
      
      
      SOURCES += main.cpp\
              widget.cpp
      
      HEADERS  += widget.h
      
      FORMS    += widget.ui
      INCLUDEPATH += /usr/include/c++/4.3
      QT += sql
      
      
      GuapoG Offline
      GuapoG Offline
      Guapo
      wrote on last edited by
      #2

      @gorkemhacioglu try put QT += core gui sql

      And take a look at [path to your qt]/gcc/plugins/sqldrivers

      ldd libqmysql.so.....if there are any link missing, I think you´ll have to recompile your driver.

      I had the same problem here with debian.

      []s

      1 Reply Last reply
      1
      • G gorkemhacioglu

        Hello everyone. I am newbie in QT. I have a problem. My compiler doesn't give me an error but i can not connect my MYSQL database. Please help, here is my code.

        #include "widget.h"
        #include "ui_widget.h"
        #include <QtGui>
        #include <QKeyEvent>
        #include <QThread>
        #include <qtextstream.h>
        #include <QProcess>
        #include <QString>
        #include<QtSql/QSqlDatabase>
        #include<QtSql/QSqlQuery>
        #include <QtSql/qsql.h>
        #include <QtSql/QSqlDatabase>
        #include <QtSql/QSqlDriver>
        #include <QtSql/QSqlQuery>
        #include <QSqlTableModel>
        #include <QtSql/QSqlError>
        
        using namespace std;
        
        Widget::Widget(QWidget *parent) :
            QWidget(parent),
            ui(new Ui::Widget)
        {
            ui->setupUi(this);
        
        
            QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
            db.setHostName("localhost");
            db.setDatabaseName("raspidb");
            db.setUserName("root");
            db.setPassword("pass1234");
            db.setPort(3306);
            if(!db.open())
               ui->label->setText("not connected");
        
        }
        
        Widget::~Widget()
        {
            delete ui;
        }
        
        
        
        

        and my .pro

        QT       += core gui
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        TARGET = untitled6
        TEMPLATE = app
        
        
        SOURCES += main.cpp\
                widget.cpp
        
        HEADERS  += widget.h
        
        FORMS    += widget.ui
        INCLUDEPATH += /usr/include/c++/4.3
        QT += sql
        
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @gorkemhacioglu Are there any warnings when you start your app (in the terminal)? Also: why don't you check for errors? See http://doc.qt.io/qt-5/qsqldatabase.html#lastError for that

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved