Hi,
QML Text controls is freezing for several second when I try to modify text from c++.
My code:
MyXML.h:
#ifndef MYXMLCLASS_H
#define MYXMLCLASS_H
#include <QObject>
{
Q_OBJECT
Q_PROPERTY(QString newPROPERTY1 READ getPROPERTY1 WRITE setPROPERTY1 NOTIFY pROPERTY1Changed
) .
.
.
Q_PROPERTY(QString newPROPERTY18 READ getPROPERTY18 WRITE setPROPERTY18 NOTIFY pROPERTY18Changed
)
public:
MyXML();
Q_INVOKABLE
QString getPROPERTY1
() const;
.
.
.
Q_INVOKABLE QString getPROPERTY18
() const;
public slots:
void setPROPERTY1
(QString pROPERTY1
);
.
.
.
void setPROPERTY18
(QString pROPERTY18
);
void saveXMLFile();
void readXMLFile();
signals:
.
.
.
private:
.
.
.
};
#endif // MYXMLCLASS_H
#ifndef MYXMLCLASS_H
#define MYXMLCLASS_H
#include <QObject>
class MyXML: public QObject
{
Q_OBJECT
Q_PROPERTY(QString newPROPERTY1 READ getPROPERTY1 WRITE setPROPERTY1 NOTIFY pROPERTY1Changed)
.
.
.
Q_PROPERTY(QString newPROPERTY18 READ getPROPERTY18 WRITE setPROPERTY18 NOTIFY pROPERTY18Changed)
public:
MyXML();
MyXML(QString);
Q_INVOKABLE QString getPROPERTY1() const;
.
.
.
Q_INVOKABLE QString getPROPERTY18() const;
public slots:
void setPROPERTY1(QString pROPERTY1);
.
.
.
void setPROPERTY18(QString pROPERTY18);
void saveXMLFile();
void readXMLFile();
signals:
void pROPERTY1Changed(QString);
.
.
.
void pROPERTY18Changed(QString);
private:
QString newPROPERTY1;
.
.
.
QString newPROPERTY18;
};
#endif // MYXMLCLASS_H
To copy to clipboard, switch view to plain text mode
MyXML.cpp:
#include <mymxl.h>
#include <QFileDialog>
#include <QXmlStreamWriter>
MyXML::MyXML()
{
newFileName = "";
}
{
newFileName = fileName;
}
QString MyXML
::getPROPERTY1() const {
return newPROPERTY1;
}
void MyXML
::setPROPERTY1(QString pROPERTY1
) {
if (pROPERTY1 != newPROPERTY1)
{
newPROPERTY1 = pROPERTY1;
emit pROPERTY1Changed(pROPERTY1);
}
}
..
..
..
..
..
QString MyXML
::getPROPERTY18() const {
return newPROPERTY18;
}
void MyXML
::setPROPERTY18(QString pROPERTY18
) {
if (pROPERTY18 != newPROPERTY18)
{
newPROPERTY18 = pROPERTY18;
emit pROPERTY18Changed(pROPERTY18);
}
}
void MyXML::saveXMLFile()
{
...
...
...
}
void MyXML::readXMLFile()
{
setPROPERTY2("neda2");
...
...
...
setPROPERTY18("neda18");
...
...
...
...
}
#include <mymxl.h>
#include <QFileDialog>
#include <QXmlStreamWriter>
MyXML::MyXML()
{
newFileName = "";
}
MyXML::MyXML(QString fileName)
{
newFileName = fileName;
}
QString MyXML::getPROPERTY1() const
{
return newPROPERTY1;
}
void MyXML::setPROPERTY1(QString pROPERTY1)
{
if (pROPERTY1 != newPROPERTY1)
{
newPROPERTY1 = pROPERTY1;
emit pROPERTY1Changed(pROPERTY1);
}
}
..
..
..
..
..
QString MyXML::getPROPERTY18() const
{
return newPROPERTY18;
}
void MyXML::setPROPERTY18(QString pROPERTY18)
{
if (pROPERTY18 != newPROPERTY18)
{
newPROPERTY18 = pROPERTY18;
emit pROPERTY18Changed(pROPERTY18);
}
}
void MyXML::saveXMLFile()
{
...
...
...
}
void MyXML::readXMLFile()
{
setPROPERTY2("neda2");
...
...
...
setPROPERTY18("neda18");
...
...
...
...
}
To copy to clipboard, switch view to plain text mode
main.qml:
Input {
id:inputPROPERTY2
text: myXML.newPROPERTY2
}
...
...
...
...
...
...
Input {
id:inputPROPERTY18
text: myXML.newPROPERTY18
}
MyToolButton{
MouseArea
{
onClicked: {
openFileDialog.open()
}
}
}
FileDialog {
id: openFileDialog
title: "please select xml file"
folder: shortcuts.home
nameFilters: [ "XML files (*.XML *.xml)" ]
selectedNameFilter: "XML files (*.XML *.xml)"
onAccepted: {
console.log("You chose: " + openFileDialog.fileUrl)
var path = openFileDialog.fileUrl.toString();
// remove prefixed "file:///"
path= path.replace(/^(file:\/{3})|(qrc:\/{2})|(http:\/{2})/,"");
myXML.setPROPERTY1(path)
myXML.readXMLFile()
}
onRejected: {
console.log("Canceled")
}
}
Input {
id:inputPROPERTY2
text: myXML.newPROPERTY2
}
...
...
...
...
...
...
Input {
id:inputPROPERTY18
text: myXML.newPROPERTY18
}
MyToolButton{
MouseArea
{
onClicked: {
openFileDialog.open()
}
}
}
FileDialog {
id: openFileDialog
title: "please select xml file"
folder: shortcuts.home
nameFilters: [ "XML files (*.XML *.xml)" ]
selectedNameFilter: "XML files (*.XML *.xml)"
onAccepted: {
console.log("You chose: " + openFileDialog.fileUrl)
var path = openFileDialog.fileUrl.toString();
// remove prefixed "file:///"
path= path.replace(/^(file:\/{3})|(qrc:\/{2})|(http:\/{2})/,"");
myXML.setPROPERTY1(path)
myXML.readXMLFile()
}
onRejected: {
console.log("Canceled")
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks