Results 1 to 3 of 3

Thread: Fix error missing ':' before identifier 'slots'

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

    Default Fix error missing ':' before identifier 'slots'

    Hi,
    I create new C++ class:

    myxmlclass.h:
    Qt Code:
    1. #ifndef MYXMLCLASS_H
    2. #define MYXMLCLASS_H
    3.  
    4.  
    5. class MyXMLClass
    6. {
    7. public:
    8. MyXMLClass();
    9.  
    10. public slots:
    11. void SaveXMLFile();
    12. void ReadXMLFile();
    13. };
    14.  
    15. #endif // MYXMLCLASS_H
    To copy to clipboard, switch view to plain text mode 

    myxmlclass.cpp:
    Qt Code:
    1. #include <myxmlclass.h>
    2. #include <QFileDialog>
    3. #include <QXmlStreamWriter>
    4.  
    5. void MyXMLClass::SaveXMLFile()
    6. {
    7.  
    8. QString filename = QFileDialog::getSaveFileName(this,
    9. tr("Save Xml"), ".",
    10. tr("Xml files (*.xml)"));
    11.  
    12.  
    13. QFile file(filename);
    14. file.open(QIODevice::WriteOnly);
    15.  
    16. QXmlStreamWriter xmlWriter(&file);
    17. xmlWriter.setAutoFormatting(true);
    18. xmlWriter.writeStartDocument();
    19.  
    20. xmlWriter.writeStartElement("LAMPS");
    21.  
    22. xmlWriter.writeStartElement("LIGHT1");
    23. xmlWriter.writeTextElement("State", "statevalue" );
    24. xmlWriter.writeTextElement("Room", "roomvalue");
    25. xmlWriter.writeTextElement("Potencial", "potencialvalue");
    26.  
    27. xmlWriter.writeEndElement();
    28.  
    29. file.close();
    30. }
    31.  
    32.  
    33.  
    34. void MyXMLClass::ReadXMLFile()
    35. {
    36. QXmlStreamReader Rxml;
    37.  
    38. QString filename = QFileDialog::getOpenFileName(this,
    39. tr("Open Xml"), ".",
    40. tr("Xml files (*.xml)"));
    41.  
    42. QFile file(filename);
    43. if (!file.open(QFile::ReadOnly | QFile::Text))
    44. {
    45. std::cerr << "Error: Cannot read file " << qPrintable(filename)
    46. << ": " << qPrintable(file.errorString())
    47. << std::endl;
    48.  
    49. }
    50.  
    51. Rxml.setDevice(&file);
    52. Rxml.readNext();
    53.  
    54. while (!Rxml.atEnd())
    55. {
    56. if (Rxml.isStartElement())
    57. {
    58. if (Rxml.name() == "LAMPS")
    59. {
    60. Rxml.readNext();
    61. }
    62. else if (Rxml.name() == "LIGHT1")
    63. {
    64. while (!Rxml.atEnd())
    65. {
    66. if (Rxml.isEndElement())
    67. {
    68. Rxml.readNext();
    69. break;
    70. }
    71. else if (Rxml.isCharacters())
    72. {
    73. Rxml.readNext();
    74. }
    75. else if (Rxml.isStartElement())
    76. {
    77. if (Rxml.name() == "State")
    78. {
    79. ReadStateElement();
    80. }
    81. else if (Rxml.name() == "Room")
    82. {
    83. ReadRoomElement();
    84. }
    85. else if (Rxml.name() == "Potencial")
    86. {
    87. ReadPotencialElement();
    88. }
    89. Rxml.readNext();
    90. }
    91. else
    92. {
    93. Rxml.readNext();
    94. }
    95. }
    96. }
    97. }
    98. else
    99. {
    100. Rxml.readNext();
    101. }
    102.  
    103. file.close();
    104.  
    105. if (Rxml.hasError())
    106. {
    107. std::cerr << "Error: Failed to parse file "
    108. << qPrintable(filename) << ": "
    109. << qPrintable(Rxml.errorString()) << std::endl;
    110. }
    111. else if (file.error() != QFile::NoError)
    112. {
    113. std::cerr << "Error: Cannot read file " << qPrintable(filename)
    114. << ": " << qPrintable(file.errorString())
    115. << std::endl;
    116. }
    117. }
    118. }
    119.  
    120.  
    121.  
    122. //Example for Room Element
    123.  
    124. void MyXMLClass::ReadRoomElement()
    125. {
    126. while(!Rxml.atEnd())
    127. {
    128. if(Rxml.isEndElement())
    129. {
    130. Rxml.readNext();
    131. break;
    132. }
    133. else if(Rxml.isStartElement())
    134. {
    135. QString roomelement = Rxml.readElementText(); //Get the xml value
    136. Rxml.readNext();
    137. break;
    138. }
    139. else if(Rxml.isCharacters())
    140. {
    141. Rxml.readNext();
    142. }
    143. else
    144. {
    145. Rxml.readNext();
    146. }
    147. }
    148.  
    149. }
    To copy to clipboard, switch view to plain text mode 

    I have syntax error : missing ':' before identifier 'slots'.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fix error missing ':' before identifier 'slots'

    Between lines 6 and 7 in myxmlclass.h add :
    Qt Code:
    1. Q_OBJECT
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lesiok for this useful post:

    neda (16th February 2016)

  4. #3
    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: Fix error missing ':' before identifier 'slots'

    Quote Originally Posted by Lesiok View Post
    Between lines 6 and 7 in myxmlclass.h add :
    Qt Code:
    1. Q_OBJECT
    To copy to clipboard, switch view to plain text mode 
    And include <QObject> and derive from QObject

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    neda (16th February 2016)

Similar Threads

  1. Error: connection identifier wrong.
    By RolandHughes in forum Qt Programming
    Replies: 19
    Last Post: 6th July 2015, 10:19
  2. syntax error : identifier 'QSqlRelationalDelegate'
    By sticcino in forum Qt Programming
    Replies: 6
    Last Post: 16th September 2011, 10:15
  3. Replies: 3
    Last Post: 12th February 2010, 10:10
  4. Replies: 3
    Last Post: 27th February 2006, 05:51
  5. Missing slots
    By Mariane in forum Newbie
    Replies: 1
    Last Post: 5th February 2006, 01:50

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.