Results 1 to 2 of 2

Thread: expected unqualified-id before public

  1. #1
    Join Date
    Apr 2015
    Qt products

    Default Re: expected unqualified-id before public

    Hi all.

    I am getting this error when compiling. But the compiler does not tell me where the error is. I am able to compile the files outside Qt creator.
    It seems that the error is in this file - if I don't include it, then it will compile and run.

    Qt Code:
    1. #ifndef DATABASE_H_
    2. #define DATABASE_H_
    4. #include <vector>
    5. #include <VirtualSignal.h>
    7. typedef enum : uint16_t
    8. {
    10. NUMBER_OF_SIGNALS = 0x0001
    11. } Signal;
    13. class DataBase
    14. {
    15. public:
    16. DataBase();
    17. VirtualSignal& getData(Signal input);
    18. uint64_t getSize();
    20. private:
    21. static std::vector<VirtualSignal> signals;
    22. };
    24. #endif /* DATABASE_H_ */
    To copy to clipboard, switch view to plain text mode 

    and the implementation

    Qt Code:
    1. #include "DataBase.h"
    3. #define LOCAL_HOST 0x7F000001
    5. std::vector<VirtualSignal> DataBase::signals;
    7. DataBase::DataBase()
    8. {
    9. for (uint16_t n=0; n<NUMBER_OF_SIGNALS; n++)
    10. signals.push_back(VirtualSignal(LOCAL_HOST, n));
    11. }
    13. VirtualSignal& DataBase::getData(Signal input)
    14. {
    15. return signals[input];
    16. };
    18. uint64_t DataBase::getSize()
    19. {
    20. return signals.size();
    21. }
    To copy to clipboard, switch view to plain text mode 

    What am I missing?

    Added after 43 minutes:

    Oh. I figured it out. The variable signals is used somewhere in qt, so somehow they conflict.
    Last edited by Clausen; 27th May 2021 at 08:56.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 803 Times in 792 Posts
    Qt products
    Windows Android

    Default Re: expected unqualified-id before public

    "signals" is a Qt keyword and is used in a class declaration to define a set of methods the Qt metaobject compiler (MOC) will use to create the boilerplate code to implement Qt signals for that class. Qt Creator's pre-compile step scans source files for this and other Qt keywords and invokes MOC.

    I am surprised, because I thought only classes derived from QObject which contain the Q_OBJECT macro declaration are supposed to be processed by MOC, because they are the only ones that can implement signals and slots. Maybe you are #include-ing this header file in a Qt class declaration header file and that is causing the error when MOC processes that file.

    You can turn off use of the MOC keywords "signals", "slots", and "emit" by defining "no_keywords" in your .pro file "config" statement. In that case, you must use the macros Q_SIGNALS, Q_SLOTS, and Q_EMIT instead and you can use the special keywords as ordinary C++ type and variable names. That's probably not a good idea because of the confusion it will inevitably cause.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. error: expected unqualified-id before numeric constant
    By Pragya in forum Qt Programming
    Replies: 28
    Last Post: 9th February 2020, 20:39
  2. Replies: 3
    Last Post: 11th February 2018, 18:00
  3. Public variables
    By eltecprogetti in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2012, 12:58
  4. Replies: 1
    Last Post: 16th February 2011, 08:06
  5. Replies: 5
    Last Post: 17th February 2009, 14:18


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.