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. QUiLoader loading CustomWidget, called setter twice

QUiLoader loading CustomWidget, called setter twice

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.7k 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.
  • F Offline
    F Offline
    Faema
    wrote on last edited by
    #1

    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?

    Pseudocode:
    .h-File
    @
    class QDESIGNER_WIDGET_EXPORT MyLineEdit : public QWidget{
    Q_OBJECT
    Q_PROPERTY(QString labelText READ getLabelText WRITE setLabelText)
    private:
    QString labelText;
    public:
    void setLabelText(const QString& labelText);
    };
    @

    cpp-File:
    @
    MyLineEdit::MyLineEdit(QWidget* parent) : QWidget(parent){}

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

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

    UI-File:
    @
    ...
    <item>
    <widget class="MyLineEdit" name="myLineEdit">
    <property name="labelText">
    <string>Test:</string>
    </property>
    </widget>
    </item>
    ...
    @

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

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

      Hi and welcome to devnet,

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

      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
      • F Offline
        F Offline
        Faema
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

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

          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
          • F Offline
            F Offline
            Faema
            wrote on last edited by
            #5

            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

            System:

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

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

            Best regards

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Faema
              wrote on last edited by
              #6

              Hi,

              can someone reproduce/confirm the behavior?

              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