Results 1 to 13 of 13

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

Hybrid 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 Re: Freezing text controls when I try to modify text from c++

    I think I'd better complete code here.

    I have 5 text field control and one tableview.

    User can add row to tableview (contain 12 column (prop6 - 16 and image)).
    I must save data (all row of tableview and text of 5 controls and one image) in XML file,
    and when I open XML file, it shows data in tableview and text controls.

    QML Text controls (propery 1 -5) is freezing for 6 second when I try to modify text from c++.

    I have no idea how to write code for this process.

    My XML file:
    Qt Code:
    1. <?xml version="1.0" standalone="yes"?>
    2. <NewDataSet>
    3. <header prop1="..." prop2="..." prop3="..." prop4="..." prop5="..." />
    4.  
    5. <record prop6=".." prop7=".." prop8="..." prop9=".." prop10=".." prop11=".." prop12="..." prop13="..." prop14=..." prop15="..." prop16="..." image="iVBORw0KGgoAAtKdOq1aPGLd/Y8QAQEprZ1a7P3oLIBAIgBRIRtcI8w/ ...." />
    6. <record prop6=".." prop7=".." prop8="..." prop9=".." prop10=".." prop11=".." prop12="..." prop13="..." prop14=..." prop15="..." prop16="..." image="iVBORw0KGgoAAtKdOq1aPGLd/Y8QAQEprZ1a7P3oLIBAIgBRIRtcI8w/ ...." />
    7. .......
    8. .......
    9. .......
    10. <record prop6=".." prop7=".." prop8="..." prop9=".." prop10=".." prop11=".." prop12="..." prop13="..." prop14=..." prop15="..." prop16="..." image="iVBORw0KGgoAAtKdOq1aPGLd/Y8QAQEprZ1a7P3oLIBAIgBRIRtcI8w/ ...." />
    11. </NewDataSet>
    To copy to clipboard, switch view to plain text mode 


    myxml.cpp:
    Qt Code:
    1. MyXML::MyXML()
    2. {
    3. newFileName = "";
    4. }
    5. MyXML::MyXML(QString pROPERTY18)
    6. {
    7. newPROPERTY18 = pROPERTY18;
    8. }
    9.  
    10. QString MyXML::getPROPERTY1() const
    11. {
    12. return newPROPERTY1;
    13. }
    14. void MyXML::setPROPERTY1(QString pROPERTY1)
    15. {
    16. if (pROPERTY1 != newPROPERTY1)
    17. {
    18. newPROPERTY1 = pROPERTY1;
    19. emit pROPERTY1Changed(pROPERTY1);
    20. }
    21. }
    22. ..
    23. ..
    24. ..
    25. ..
    26. ..
    27.  
    28. QString MyXML::getPROPERTY18() const
    29. {
    30. return newPROPERTY18;
    31. }
    32. void MyXML::setPROPERTY18(QString pROPERTY18)
    33. {
    34. if (pROPERTY18 != newPROPERTY18)
    35. {
    36. newPROPERTY18 = pROPERTY18;
    37. emit pROPERTY18Changed(pROPERTY18);
    38. }
    39. }
    40.  
    41. void MyXML::saveXMLFile()
    42. {
    43. QXmlStreamWriter xmlWriter(&file);
    44. xmlWriter.setAutoFormatting(true);
    45. xmlWriter.writeStartDocument();
    46.  
    47. xmlWriter.writeStartElement("NewDataSet");
    48.  
    49. xmlWriter.writeStartElement("header");
    50. xmlWriter.writeAttribute("pROPERTY1",newpROPERTY1);
    51. xmlWriter.writeAttribute("pROPERTY2",newpROPERTY2);
    52. xmlWriter.writeAttribute("pROPERTY3",newpROPERTY3);
    53. xmlWriter.writeAttribute("pROPERTY4",newpROPERTY4);
    54. xmlWriter.writeAttribute("pROPERTY5",newpROPERTY5);
    55. xmlWriter.writeEndElement();
    56.  
    57. ????? save data of tableview
    58.  
    59. xmlWriter.writeEndElement();
    60.  
    61. file.close();
    62. }
    63. }
    64.  
    65.  
    66. void MyXML::readXMLFile()
    67. {
    68. QFile file(pROPERTY18);
    69. if (!file.open(QFile::ReadOnly | QFile::Text))
    70. {
    71. //qDebug() << "Error: Cannot read file ";
    72. return;
    73. }
    74. QXmlStreamReader reader(file.readAll());
    75. file.close();
    76. while(!reader.atEnd()) {
    77. reader.readNext();
    78. if (reader.isStartElement()) {
    79. if (reader.name() == "header") {//After about 6 seconds the text is displayed in controls
    80. foreach(const QXmlStreamAttribute &attr, reader.attributes()) {
    81. if(attr.name().toString() == QLatin1String("pROPERTY1")){
    82. setpROPERTY1(attr.value().toString());
    83. }
    84. else if(attr.name().toString() == QLatin1String("pROPERTY2")){
    85. setpROPERTY2(attr.value().toString());
    86. }
    87. else if(attr.name().toString() == QLatin1String("pROPERTY3")){
    88. setpROPERTY3(attr.value().toString());
    89. }
    90. else if(attr.name().toString() == QLatin1String("pROPERTY4")){
    91. setpROPERTY4(attr.value().toString());
    92. }
    93. else if(attr.name().toString() == QLatin1String("pROPERTY5")){
    94. setpROPERTY5(attr.value().toString());
    95. }
    96. }
    97. }
    98. else if (reader.name() == "recorde") {
    99.  
    100. ?????????
    101.  
    102. }
    103. }
    104. }
    105. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by neda; 23rd February 2016 at 08:16.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    Your comment suggests that you get the freezing when updating the values during XML parsing, but earlier you said it would happen even when not loading from XML?

    In any case you will need a model to handle the table, see http://doc.qt.io/qt-5/qtquick-modelv...tractitemmodel

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

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

    Quote Originally Posted by anda_skoa View Post
    Your comment suggests that you get the freezing when updating the values during XML parsing, but earlier you said it would happen even when not loading from XML?

    _
    Yes, it would happen even when not loading from XML.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

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

    Ok, very strange.

    Can you provide/attach a minimal program that shows the problem?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

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

    Quote Originally Posted by anda_skoa View Post
    Ok, very strange.

    Can you provide/attach a minimal program that shows the problem?

    _
    Thank you.
    I figure out my problem.

    This problem will happen when I open th file name is not English..
    Is there a way to solve this problem?
    Last edited by neda; 24th February 2016 at 10:08.

  6. #6
    Join Date
    Dec 2015
    Location
    Austria
    Posts
    23
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

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

    What is a "non-English name" ???

  7. #7
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

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

    I mean the file name is not English.

  8. #8
    Join Date
    Dec 2015
    Location
    Austria
    Posts
    23
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

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

    Thats no serious answer.... A german or italian or french filename will work too.
    Do you mean a filename with another charset?

    You may try the "decodeName" method on the QFile class
    Last edited by ChriD; 24th February 2016 at 11:34.

  9. The following user says thank you to ChriD for this useful post:

    neda (24th February 2016)

  10. #9
    Join Date
    Jan 2016
    Posts
    81
    Thanks
    31
    Qt products
    Qt5
    Platforms
    Windows

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

    Quote Originally Posted by ChriD View Post

    You may try the "decodeName" method on the QFile class
    Yes,Thank you. my problem is solved.
    Last edited by neda; 24th February 2016 at 11:53.

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
  •  
Qt is a trademark of The Qt Company.