QUiLoader loading CustomWidget, called setter twice

  • Hello,

    i have a question about the QUiLoader. I load an ui-file with quiloader.load(&file). The ui-file contains some customwidget. The setters from my customwidgets are always called twice. I wondering if i do something wrong or is it a bug?

    My problem is, that i have a setter that does slightly more complex things and i dont want to work with flags in the setter like "if(notAlreadyDone){...}". Any ideas how i can avoid that?

    class QDESIGNER_WIDGET_EXPORT MyLineEdit : public QWidget{
    Q_PROPERTY(QString labelText READ getLabelText WRITE setLabelText)
    QString labelText;
    void setLabelText(const QString& labelText);

    MyLineEdit::MyLineEdit(QWidget* parent) : QWidget(parent){}

    void MyLineEdit::setLabelText(const QString& labelText){
    qDebug() << PRETTY_FUNCTION << "LabelText:" << labelText;
    this->labelText = labelText;

    qDebug() << "--> before" << uiMaskFileName;
    QUiLoader loader;
    QWidget* parent = new QWidget();
    QWidget* formWidget = loader.load(&file, parent);
    qDebug() << "--> after";

    <widget class="MyLineEdit" name="myLineEdit">
    <property name="labelText">

    --> before "/tmp/my.ui"
    void MyLineEdit::setLabelText(const QString&) LabelText: "Test:"
    void MyLineEdit::setLabelText(const QString&) LabelText: "Test:"
    --> after

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure that in your custom widget you don't have multiple connect calls ?

  • Hi,

    thanks for your reply.

    Yes i am sure. I wrote a test-class with only 1 constructor and 1 set-/getter. No additional signal/slots/connects.

  • Lifetime Qt Champion

    Can you share a minimal compilable example that shows the behavior ?

    Also, what version of Qt and what OS are you running on ?

  • Hi,

    i have created some files/projects similar to my real project.

    I uploaded a zipfile to a sharing site, because i saw no possiblity to upload files here.

    The zipfile contains:

    • 1 designer lib
    • 1 shared lib
    • 1 main-program
    • 1 ui-file
    • 1 Readme


    • Qt-version is 5.2.0
    • OS openSuse 12.1
    • IDE Eclipse

    "Download zip":http://www.fileconvoy.com/dfl.php?id=g6da5f12a22f919f09995252123a96d0dc5e4d0085

    Best regards

  • Hi,

    can someone reproduce/confirm the behavior?

Log in to reply

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