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. no connection with qsqlite

no connection with qsqlite

Scheduled Pinned Locked Moved Solved Installation and Deployment
16 Posts 4 Posters 1.3k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    FloCGN
    wrote on last edited by FloCGN
    #1

    Hello, I'm new to the forum and I hope you can help me.

    I successfully created my first form with QDesigner in python3 and then wanted to connect to my SQLite database.

    What I have done wrong ? I use SQlite 3.3.3 and pyside6-6.2.3

    from PySide6.QtWidgets import QApplication,QMainWindow
    from PySide6 import QtSql
    from QT.frm_main import Ui_frm_main
    
    
    class Frm_main(QMainWindow, Ui_frm_main):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            mod_offene_Leistungen = QtSql.QSqlRelationalTableModel()
            mod_offene_Leistungen.setTable("Leistungen")
            mod_offene_Leistungen.select()
            self.tbl_offene_Leistungen.setModel(mod_offene_Leistungen)
    
    
    db=QtSql.QSqlDatabase.addDatabase("QSQLITE")
    db.setDatabaseName("Rechnungen.db")
    
    
    
    app=QApplication()
    frm_main=Frm_main()
    frm_main.show()
    app.exec()
    
    

    Bild 22.02.22 um 18.28.jpg

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Maybe you should open the database as described in the documentation?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      F 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Maybe you should open the database as described in the documentation?

        F Offline
        F Offline
        FloCGN
        wrote on last edited by
        #3

        @Christian-Ehrlicher can you send me the code according to the documentation above ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          Do you mean the code from the Python documentation of the class ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          F 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            Do you mean the code from the Python documentation of the class ?

            F Offline
            F Offline
            FloCGN
            wrote on last edited by
            #5

            @SGaist I just want to include the "Rechnungen.db" database. For this I want to display the "Leistungen" table in "tbl_offene_leistungen" in my gui. It's my first code, it would be great if someone could show me a sample here.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              As already suggested by @Christian-Ehrlicher, you are missing a call to the open method of your db object.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              F 1 Reply Last reply
              0
              • SGaistS SGaist

                As already suggested by @Christian-Ehrlicher, you are missing a call to the open method of your db object.

                F Offline
                F Offline
                FloCGN
                wrote on last edited by FloCGN
                #7

                @SGaist the code should then look like this ??

                db=QtSql.QSqlDatabase.addDatabase("QSQLITE")
                db.setDatabaseName("Rechnungen.db")
                db.open()
                

                It doesn’t work..

                sry for the stupid questions

                jsulmJ 1 Reply Last reply
                0
                • F FloCGN

                  @SGaist the code should then look like this ??

                  db=QtSql.QSqlDatabase.addDatabase("QSQLITE")
                  db.setDatabaseName("Rechnungen.db")
                  db.open()
                  

                  It doesn’t work..

                  sry for the stupid questions

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @FloCGN said in no connection with qsqlite:

                  It doesn’t work

                  What exactly does not work now?
                  What does db.open() return?

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

                  F 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @FloCGN said in no connection with qsqlite:

                    It doesn’t work

                    What exactly does not work now?
                    What does db.open() return?

                    F Offline
                    F Offline
                    FloCGN
                    wrote on last edited by FloCGN
                    #9

                    @jsulm

                    I want to display the "Leistungen" table in the "offene Leistungen" field. But nothing happens

                    Bildschirmfoto 2022-02-23 um 18.12.59.png

                    when I write in the terminal db.open(), then this happens:

                    Bildschirmfoto 2022-02-23 um 18.20.07.png

                    from PySide6.QtWidgets import QApplication,QMainWindow
                    from PySide6 import QtSql
                    from QT.frm_main import Ui_frm_main
                    
                    
                    class Frm_main(QMainWindow, Ui_frm_main):
                        def __init__(self):
                            super().__init__()
                            self.setupUi(self)
                            mod_offene_Leistungen = QtSql.QSqlRelationalTableModel()
                            mod_offene_Leistungen.setTable("Leistungen")
                            mod_offene_Leistungen.select()
                            self.tbl_offene_Leistungen.setModel(mod_offene_Leistungen)
                            
                            
                    
                    
                    db=QtSql.QSqlDatabase.addDatabase("QSQLITE")
                    db.setDatabaseName("Rechnungen.sqlite")
                    db.open()
                    
                    
                    
                    app=QApplication()
                    frm_main=Frm_main()
                    frm_main.show()
                    app.exec()
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Where is that file located on your system ?
                      SQLite will create the file if it does not exists hence if your path is wrong you will have an empty database.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      F 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Where is that file located on your system ?
                        SQLite will create the file if it does not exists hence if your path is wrong you will have an empty database.

                        F Offline
                        F Offline
                        FloCGN
                        wrote on last edited by
                        #11

                        @SGaist The file is in the same folder as the .py file

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Then did you check the content of the file ?
                          What about adding error checks to your code ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          F 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Then did you check the content of the file ?
                            What about adding error checks to your code ?

                            F Offline
                            F Offline
                            FloCGN
                            wrote on last edited by
                            #13

                            @SGaist the content of the database file ? I think its right

                            error checks are debugging functions ? I debugged it, but there were no error messages. I don't know if I did it right either. Like I said, I'm a total beginner

                            jsulmJ 1 Reply Last reply
                            0
                            • F FloCGN

                              @SGaist the content of the database file ? I think its right

                              error checks are debugging functions ? I debugged it, but there were no error messages. I don't know if I did it right either. Like I said, I'm a total beginner

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @FloCGN said in no connection with qsqlite:

                              I think its right

                              You think or you know?

                              "error checks are debugging functions ?" - no.
                              What does db.open() return? And please do not post some screen-shot, print it out!

                              print(db.open())
                              

                              If it returns false then check https://doc.qt.io/qt-5/qsqldatabase.html#lastError

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

                              F 1 Reply Last reply
                              1
                              • jsulmJ jsulm

                                @FloCGN said in no connection with qsqlite:

                                I think its right

                                You think or you know?

                                "error checks are debugging functions ?" - no.
                                What does db.open() return? And please do not post some screen-shot, print it out!

                                print(db.open())
                                

                                If it returns false then check https://doc.qt.io/qt-5/qsqldatabase.html#lastError

                                F Offline
                                F Offline
                                FloCGN
                                wrote on last edited by
                                #15

                                @jsulm said in no connection with qsqlite:

                                https://doc.qt.io/qt-5/qsqldatabase.html#lastError

                                it returns TRUE

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  FloCGN
                                  wrote on last edited by
                                  #16

                                  I rewrote the code again and now it works somehow... Thanks anyway to everyone

                                  1 Reply Last reply
                                  0

                                  • Login

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