Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Save data into database

Save data into database

Scheduled Pinned Locked Moved General and Desktop
databaseqcombobox
6 Posts 2 Posters 2.0k 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.
  • M Offline
    M Offline
    Mr. Kibu
    wrote on 5 May 2015, 11:58 last edited by
    #1

    Hello!

    I want to whrite data into a database (SQLite).

    I have got a QDialog with some QComboboxes and I want to write that data into a database (SQLite).

    I have already a connection do the database, set a new QSqlRelationalTableModel with some relations and mapped that model with a QDataWidgetMapper to the QComboboxes. It works fine.

    Then I have set the "setEditStrategy" of the QSqlRelationalModel to "OnManualSubmit" and added a funktion to save the data in the database (with myModel->database().commit()). It works also very fine.

    The Problem:
    I have got also a QCombobox in the Dialog, whose data I set after editing an other QCombobox (I want to set a correspondig default value)
    The Code:

    // select KsGrKey from the Source-Combo
    QModelIndex id = ui->txtKsKey->model()->index(index, 6);
    QString _KsGr = id.data().toString();
    
    // set the correspondig Value of the second Combobox, that is also mapped with the model!!!
    ui->txtKsGr->setCurrentIndex(ui->txtKsGr->findText(_KsGr)); //auf KsGr-Combo den Wert setzen
    

    In the Dialog it also works fine, it shows the value in the second combobox I want to see. But when I save the data the way I have explained above (with myModel->database().commit()), the data of the second Combobox is not written into the database.

    Has anybody an idea what I am doing wrong??

    Thank you!

    Franz

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mr. Kibu
      wrote on 5 May 2015, 18:11 last edited by
      #2

      Addition:

      If I set a value in the corresponding Combobox by hand and save the data, than the value is written into the database as I want it.
      Is the method I am using to write the value to the corresponding Combobox the right?
      Is there an additional function to write the data into the database?

      Thank's for help

      Franz

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 5 May 2015, 22:50 last edited by
        #3

        Hi and welcome to devnet,

        Are you using a QDataWidgetMapper in your dialog ?

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

        M 1 Reply Last reply 6 May 2015, 05:01
        0
        • S SGaist
          5 May 2015, 22:50

          Hi and welcome to devnet,

          Are you using a QDataWidgetMapper in your dialog ?

          M Offline
          M Offline
          Mr. Kibu
          wrote on 6 May 2015, 05:01 last edited by
          #4

          @SGaist

          Yes!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 6 May 2015, 21:20 last edited by
            #5

            Might be silly but did you check that the second combo box contains the right value before saving the content of your mapper ?

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mr. Kibu
              wrote on 18 May 2015, 06:00 last edited by
              #6

              Ok, first there was a mistake in the related datamodel of the corresponding combobox, and than there was a mistake in the submit-function. Now it works!!

              Bye!

              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