Results 1 to 13 of 13

Thread: Freezing text controls when I try to modify text from c++

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

    Default Freezing text controls when I try to modify text from c++

    Hi,
    QML Text controls is freezing for several second when I try to modify text from c++.

    My code:

    MyXML.h:
    Qt Code:
    1. #ifndef MYXMLCLASS_H
    2. #define MYXMLCLASS_H
    3.  
    4. #include <QObject>
    5.  
    6. class MyXML: public QObject
    7. {
    8. Q_OBJECT
    9. Q_PROPERTY(QString newPROPERTY1 READ getPROPERTY1 WRITE setPROPERTY1 NOTIFY pROPERTY1Changed)
    10. .
    11. .
    12. .
    13. Q_PROPERTY(QString newPROPERTY18 READ getPROPERTY18 WRITE setPROPERTY18 NOTIFY pROPERTY18Changed)
    14.  
    15. public:
    16. MyXML();
    17. MyXML(QString);
    18. Q_INVOKABLE QString getPROPERTY1() const;
    19. .
    20. .
    21. .
    22. Q_INVOKABLE QString getPROPERTY18() const;
    23.  
    24. public slots:
    25. void setPROPERTY1(QString pROPERTY1);
    26. .
    27. .
    28. .
    29. void setPROPERTY18(QString pROPERTY18);
    30.  
    31. void saveXMLFile();
    32. void readXMLFile();
    33.  
    34. signals:
    35. void pROPERTY1Changed(QString);
    36. .
    37. .
    38. .
    39. void pROPERTY18Changed(QString);
    40.  
    41. private:
    42. QString newPROPERTY1;
    43. .
    44. .
    45. .
    46. QString newPROPERTY18;
    47. };
    48.  
    49. #endif // MYXMLCLASS_H
    To copy to clipboard, switch view to plain text mode 

    MyXML.cpp:

    Qt Code:
    1. #include <mymxl.h>
    2. #include <QFileDialog>
    3. #include <QXmlStreamWriter>
    4.  
    5. MyXML::MyXML()
    6. {
    7. newFileName = "";
    8. }
    9. MyXML::MyXML(QString fileName)
    10. {
    11. newFileName = fileName;
    12. }
    13.  
    14. QString MyXML::getPROPERTY1() const
    15. {
    16. return newPROPERTY1;
    17. }
    18. void MyXML::setPROPERTY1(QString pROPERTY1)
    19. {
    20. if (pROPERTY1 != newPROPERTY1)
    21. {
    22. newPROPERTY1 = pROPERTY1;
    23. emit pROPERTY1Changed(pROPERTY1);
    24. }
    25. }
    26. ..
    27. ..
    28. ..
    29. ..
    30. ..
    31.  
    32. QString MyXML::getPROPERTY18() const
    33. {
    34. return newPROPERTY18;
    35. }
    36. void MyXML::setPROPERTY18(QString pROPERTY18)
    37. {
    38. if (pROPERTY18 != newPROPERTY18)
    39. {
    40. newPROPERTY18 = pROPERTY18;
    41. emit pROPERTY18Changed(pROPERTY18);
    42. }
    43. }
    44.  
    45. void MyXML::saveXMLFile()
    46. {
    47. ...
    48. ...
    49. ...
    50. }
    51.  
    52. void MyXML::readXMLFile()
    53. {
    54. setPROPERTY2("neda2");
    55. ...
    56. ...
    57. ...
    58. setPROPERTY18("neda18");
    59.  
    60. ...
    61.  
    62. ...
    63. ...
    64. ...
    65.  
    66.  
    67. }
    To copy to clipboard, switch view to plain text mode 


    main.qml:

    Qt Code:
    1. Input {
    2. id:inputPROPERTY2
    3. text: myXML.newPROPERTY2
    4.  
    5. }
    6.  
    7. ...
    8. ...
    9. ...
    10. ...
    11. ...
    12. ...
    13. Input {
    14. id:inputPROPERTY18
    15. text: myXML.newPROPERTY18
    16.  
    17. }
    18.  
    19. MyToolButton{
    20.  
    21. MouseArea
    22. {
    23.  
    24. onClicked: {
    25. openFileDialog.open()
    26. }
    27.  
    28. }
    29.  
    30. }
    31. FileDialog {
    32. id: openFileDialog
    33. title: "please select xml file"
    34. folder: shortcuts.home
    35. nameFilters: [ "XML files (*.XML *.xml)" ]
    36. selectedNameFilter: "XML files (*.XML *.xml)"
    37.  
    38. onAccepted: {
    39. console.log("You chose: " + openFileDialog.fileUrl)
    40. var path = openFileDialog.fileUrl.toString();
    41. // remove prefixed "file:///"
    42. path= path.replace(/^(file:\/{3})|(qrc:\/{2})|(http:\/{2})/,"");
    43.  
    44. myXML.setPROPERTY1(path)
    45. myXML.readXMLFile()
    46. }
    47. onRejected: {
    48. console.log("Canceled")
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by neda; 22nd February 2016 at 09:25.

Similar Threads

  1. modify a QML Text from C++
    By neda in forum Qt Quick
    Replies: 7
    Last Post: 16th February 2016, 09:04
  2. Replies: 1
    Last Post: 11th May 2014, 08:29
  3. Replies: 1
    Last Post: 24th April 2010, 15:31
  4. How to modify the content of text file
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 31st July 2009, 10:23
  5. how to modify the text of node in xml docment?
    By GChen in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2009, 10:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.