Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Issues with QFormBuilder - All properties modified & Invalid UI



  • Hi,

    I am trying to use the QFormBuilder to load and later save a ".ui" file.
    The issue is that the generated file shows all properties as modified but the code just open the file and save it with a new name.

    Here is the code part that matters: (i can upload all the needed files to a Gist)

    #include "mainwindow.h"
    #include <QFormBuilder>
    #include <QFile>
    #include <QMessageBox>
    #include <QVBoxLayout>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        QFormBuilder builder;
        QFile file(":/myform.ui");
        file.open(QFile::ReadOnly);
        QWidget *myWidget = builder.load(&file, this);
        if (myWidget == nullptr) {
            QString msg = tr("Loading UI file failed: %1").arg(builder.errorString());
            QMessageBox::critical(this, tr("Error"), msg, QMessageBox::Ok, QMessageBox::NoButton);
        }
        file.close();
    
        // Save the form as a UI file.
        QFile saveFile("savedform.ui");
        saveFile.open(QFile::WriteOnly);
        builder.save(&saveFile, myWidget);
        saveFile.close();
    }
    

    Also, when loading the new ".ui" file with the QtDesigner the widgets are not displayed properly.
    Is there a better approach to save QWidgets as ".ui" from code?

    Thank you!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What properties as different ?

    If for example size related, a widget that hasn't been shown doesn't have a size.



  • @SGaist thank you!

    The generated ui file should be exactly the same as the ui that was ingested by the QFormBuilder.
    But that is not what happens. Check the output at this [GitHub Gist link] (https://gist.github.com/hhslepicka/0808febcbd9e301612b40012e0b0037d) (too big to fit properly here)

    My Qt Version: 5.12.3. I tested it with MacOS and Linux... same behavior.

    When I open the generated file with the QtDesigner it presents an invalid UI that does not look like the original file.

    Here is the original form with Qt Designer
    Screen Shot 2019-10-17 at 4.34.56 PM.png

    And here is how it looks like after passing through the QFormBuilder:
    Screen Shot 2019-10-17 at 4.35.13 PM.png

    Note the <noname> widgets, how it renders completely different than the original UI and if you look closely at the "Property Editor", all properties are showing as changed (bold) which is also incorrect.

    Another interesting point is that during the "save" phase, the QFormBuilder prints the following messages:

    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: The property document could not be written. The type QTextDocument* is not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    Designer: Flags property are not supported yet.
    

  • Lifetime Qt Champion

    Hi
    Just as a note:
    i tried your code with Creator
    I made a QMainWindow ui and placed some widgets on it.
    Then i round-tripped that.
    The resulting UI file crashes Creator and is unloadable.

    Then i tried a completely blank QMainWindow
    and while Creator did not crash then, the resulting
    UI file is very messed up.

    alt text

    and i also saw the
    "Designer: Flags property are not supported yet."

    So its not even close to being round trip. its
    completely broken.

    So either we have very wrong expectations of what QFormBuilder
    can do/works or something is missing in how we use it.
    It hard to believe the Designer/Creator uses the same QFormBuilder
    class as the results are so way of.



  • @mrjj I'm glad you tested and reached the same fault result.
    I agree with your statement at the end...
    Either we have wrong expectations or we are missing something.
    According to the Qt documentation (https://doc.qt.io/qt-5/qabstractformbuilder.html#save) it is my understanding that the QFormBuilder would generate a valid UI using the standard format. Even if it presents all properties as "modified" that should not be a problem for the Qt Designer or even Qt Creator to display the newly generated UI after the "round trip".

    Thank you both for looking into it.


  • Lifetime Qt Champion

    @hhslepicka
    Hi
    I had 100% the same expectations as you but only used the QUILoader class.
    I never used the save ability of QFormBuilder but did read about it and
    was 100% sure until your post that it would perfectly roundtrip as it was the same as in Designer/Creator and
    hence would work the same.

    I would ask on
    https://lists.qt-project.org/listinfo/development
    where the developers is.
    It would be nice to know if its really something else than what Designer uses.
    (as that would explain alot)

    I also tried other tests and go nothing valid from saving it.
    Its not just a matter of a few properties being a bit off.
    Often the resulting file has odd nameless widget and other elements
    that seems to come from nowhere.

    I looked at the docs a few times but i could not spot anythingthat would even hint or suggest these
    result.

    So if its not broken ( regression) Im not really sure what is going on.



  • @mrjj

    Good call! I just posted the issue there. Here is the link in case you want also to follow up: https://lists.qt-project.org/pipermail/development/2019-October/037738.html

    I will update the post here as soon as I hear back from the developers.


  • Lifetime Qt Champion

    @hhslepicka
    Super.
    And fine post.
    All details and test sample.

    one thing i did not test yet.
    Like you i also used a UI file in a resource.
    I wondered for a moment if it needed to fixup the source file somehow and was blocked by it
    being readonly but it seems very unlikely.

    Also the docs does really, really sounds like any UI can be used and does not mention any restriction or
    similar notes.
    So Im a very curious on what the truth is :)


  • Lifetime Qt Champion

    I'd say that designer has its own QFormBuilder subclass.



  • @SGaist
    Hi,

    Looking at the code there looks like it just adds some functionality to hook up to the Designer UI but other than that, it makes calls to the QFormBuilder, which is kind of what we expected that Designer and Creator would do.

    I am looking now at how the QtDesigner writes the file to disk... maybe this will shine some light as well.



  • Just to update the message here in this thread, the discussion if this should be considered a bug or not is being carried at the Qt Developers mailing list.
    Your input on the subject would be appreciated since part of developers think that the method should not be used and the other part agrees that it is a bug.


Log in to reply