Field does not get saved correctly

  • 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" "">
    <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)

  • Qt Champions 2017

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

  • 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();

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

  • 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 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?

  • I resolved it this way:

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

    Is this the correct way?

  • Qt Champions 2017

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

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.