Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.7.0
-
None
-
* ArchLinux x64
* KDE5
* Qt 5.7.0
Description
I don't know how to correctly rephrase this "magic" issue and behavior, this reproduces on Linux (at least on Linux).
Reproducing:
1. Derive own class from QSlider
2. Define the getter/setter/signal, named as setText/text/textChanged
3. Define the Q_PROPERTY for this set of methods.
4. Add the qDebug() into setText() method.
5. Call the method setText() once.
Expectation:
1. The method setText() calls once.
Observation:
1. The method setText() calls twice. o_O
2. Second call of method contains the input parameter with the trash.. E.g. if I call this with setText(tr("Foo")), then second call contains the text as "&Foo" instead of "Foo".
Workarounds:
1. If try to comments out the Q_PROPERTY macro, then this "effect" does not happens.
2. If try to rename the "text" property to, e.g. "legend" property, then this "effect" does not happens too.
3. If derive own class from QWidget or QAbstractSlider, then this "effect" does not happens.
Source:
== widget.h ==
#ifndef WIDGET_H #define WIDGET_H #include <QSlider> class Widget : public QSlider { Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) public: explicit Widget(QWidget *parent = 0); void setText(const QString &text); QString text() const; signals: void textChanged(const QString &text); private: QString m_text; }; #endif // WIDGET_H
== widget.cpp ==
#include "widget.h" #include <QDebug> Widget::Widget(QWidget *parent) : QSlider(parent) { } void Widget::setText(const QString &text) { qDebug() << Q_FUNC_INFO << text; if (m_text != text) { m_text = text; emit textChanged(m_text); } } QString Widget::text() const { return m_text; }
== main.cpp ==
#include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.setText(QApplication::tr("Foo")); w.show(); return a.exec(); }
Output:
void Widget::setText(const QString&) "Foo"
void Widget::setText(const QString&) "&Foo"
O_O
PS:Please look the source project to reproduce an issue.