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. Field does not get saved correctly
Forum Updated to NodeBB v4.3 + New Features

Field does not get saved correctly

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.1k 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.
  • P Offline
    P Offline
    Panoss
    wrote on last edited by Panoss
    #1

    I 'm working with a SQLite db, I use QSqlRelationalTableModel.
    I use model->submitAll() to save a new record.
    Let's say my field contains "a".
    In my database, in the respective field, what gets stored with "model->submitAll()" is not just "a", but a whole bunch of html code!!:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
    <html><head><meta name="qrichtext" content="1" /><style type="text/css">
    p, li { white-space: pre-wrap; }
    </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">a</p></body></html>
    

    Why is this happening? How can I fix it?

    (same happens with all my text fields, int fields get saved correctly)

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You call wrong function to get text and save the HTML instead ?

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Panoss
        wrote on last edited by Panoss
        #3

        Hi mrjj.
        I call no function at all to get text.
        The whole code in save button is this:

        void RepairDevices::on_saveButton_clicked()
        {
            int row = mapper->currentIndex();
            model->submitAll();
            mapper->setCurrentIndex(row);
            updateButtons(row);
        }
        

        No where in my program I have any html code...

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Panoss
          wrote on last edited by Panoss
          #4

          In Qt Creator 's Designer:
          I right - clicked a QEditText I have in my form...and I saw an option "Change Html...".
          I selected it and...it has html!! The default content of QEditText is html code!!!
          This is probably being submitted with model->submitAll()!!
          How do I get rid off this?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Panoss
            wrote on last edited by Panoss
            #5

            I resolved it this way:

            model->setData(model->index(row, model->fieldIndex("model")), ui.model_txt->toPlainText());
            model->submitAll();
            

            Is this the correct way?

            mrjjM 1 Reply Last reply
            1
            • P Panoss

              I resolved it this way:

              model->setData(model->index(row, model->fieldIndex("model")), ui.model_txt->toPlainText());
              model->submitAll();
              

              Is this the correct way?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @Panoss ¨
              Well to toPlainText is. That is how to get non html text.
              if still stupid try using a QPlainTextEdit instead.

              1 Reply Last reply
              1
              • P Offline
                P Offline
                Panoss
                wrote on last edited by
                #7

                I replaced them with QPlainTextEdit textboxes and so the code:

                model->setData(model->index(row, model->fieldIndex("model")), ui.model_txt->toPlainText());
                

                is not needed.

                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