Qt ошибка expected unqualified id before token

Porting my project from Qt4 to Qt5.1, I get this error from a Qt file:

C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtGui\qopenglversionfunctions.h:785: error: expected unqualified-id before ')' token
     void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);
                                           ^

This is the chain of defines:

#define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *
#define QOPENGLF_APIENTRY APIENTRY
#define APIENTRY WINAPI
#define WINAPI __stdcall

I noticed that the «MemoryBarrier» token is present in the libQt5OpenGLExtensionsd.a library. Should I include it, even if in the original Qt4 project nothing related to OpenGL was used?

Platform:
Windows 7
MinGW 4.8
Qt 4.8 —> Qt 5.1

László Papp's user avatar

László Papp

52k39 gold badges111 silver badges135 bronze badges

asked Sep 11, 2013 at 11:16

Pietro's user avatar

0

Besides the bug in MinGW 4.8.1 with uint64_t in io.h, there is also this one in QT 5.2.1 still. I came across this today when trying to compile QT 5.2.1 with MinGW 4.8.1, so I thought I would post my solution as well.

I don’t know what the official fix will be for QT, but for my needs I did it like this:

in src/gui/opengl/qopengl.h line 49:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
#endif

I just undefined the windows MemoryBarrier macro there:

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
# undef MemoryBarrier
#endif

answered Feb 19, 2014 at 5:46

Brian Onn's user avatar

Brian OnnBrian Onn

1,02611 silver badges18 bronze badges

3

I noticed that the «MemoryBarrier» token is present in the
libQt5OpenGLExtensionsd.a library. Should I include it, even if in the
original Qt4 project nothing related to OpenGL was used?

No, those are not related. OpenGLExtension is compiled after QtGui.

What you are hitting unfortunately is that there is a MemoryBarrier() already defined on Windows, and hence there is a clash for that and what qt is having. You can find the official Windows documentation for that:

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v=vs.85).aspx

I have just discussed this with Gunnar, the QtGui maintainer, and I am planning to submit a change to Gerrit to address your issue.

We had used something like this in our project a couple of years ago when we were writing thread-safe singletons based on QtCore:

#if defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 4    
#define __MEMBARRIER __sync_synchronize();  
#elif defined _MSC_VER && defined _WIN64    
#define __MEMBARRIER MemoryBarrier();   
#else   
#define __MEMBARRIER
#endif

Qt may need to check ifdef MINGW/GCC/VERSION and undef the MemoryBarrier define.

EDIT: This was fixed about half a year ago. See the following Gerrit review and the corresponding bug report for details:

https://codereview.qt-project.org/#change,68156

and

https://bugreports.qt.io/browse/QTBUG-34080

So, update to Qt 5.2.0 and it will work. Failing that, you can try to backport it.

MBach's user avatar

MBach

1,64716 silver badges30 bronze badges

answered Sep 12, 2013 at 7:22

László Papp's user avatar

László PappLászló Papp

52k39 gold badges111 silver badges135 bronze badges

14

I run into the same problem. I could compile and run with just commenting out the problematic line:

// void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);

In file C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/QtGui/qopenglversionfunctions.h:785

My application does not use any OpenGL stuff. Let’s hope they fix it soon ;-)

answered Dec 12, 2013 at 3:48

adler's user avatar

adleradler

9491 gold badge9 silver badges10 bronze badges

Since the accepted answer doesn’t seem to help when one tries to build the QT library on it’s own and Laszlo Pap claims that thie other solution is not a proper fix, I tried to find a way to fix it correctly. On Google I found a posting where it was said that MemoryBarrier is not implemented in MingW and there was a patch for it.

So I tried to incorporate the fix into opengl.h and hope that this is the correct way as simply commenting out the lines may cause problems later on.

#ifndef QT_NO_OPENGL

// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)

# include <QtCore/qt_windows.h>

#if defined(__MINGW32__) && defined(MemoryBarrier)
#undef MemoryBarrier

__CRT_INLINE void MemoryBarrier(void)
{
    long Barrier = 0;
    __asm__ __volatile__("xchgl %%eax,%0 "
        :"=r" (Barrier));
}
#endif

#endif

answered Mar 27, 2014 at 8:19

Devolus's user avatar

DevolusDevolus

21.7k13 gold badges66 silver badges113 bronze badges

1

  1. 17th February 2009, 13:06


    #1

    Exclamation weird error: expected unqualified-id before ‘…’ token

    The .ui file:

    1. <ui version="4.0" >

    2. <class>FormOutput</class>

    3. <widget class="QWidget" name="FormOutput" >

    4. <property name="geometry" >

    5. <rect>

    6. <x>0</x>

    7. <y>0</y>

    8. <width>252</width>

    9. <height>260</height>

    10. </rect>

    11. </property>

    12. <property name="windowTitle" >

    13. <string>Form</string>

    14. </property>

    15. <property name="styleSheet" >

    16. <string notr="true" >border: 1 solid black;</string>

    17. </property>

    18. <layout class="QHBoxLayout" >

    19. <item>

    20. <widget class="QTextBrowser" name="textBrowser" >

    21. <property name="frameShape" >

    22. <enum>QFrame::StyledPanel</enum>

    23. </property>

    24. <property name="html" >

    25. <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

    26. &lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">

    27. p, li { white-space: pre-wrap; }

    28. &lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">

    29. &lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;">.. initialising program..done&lt;/p>&lt;/body>&lt;/html></string>

    30. </property>

    31. </widget>

    32. </item>

    33. </layout>

    34. </widget>

    35. <resources/>

    36. <connections/>

    37. </ui>

    To copy to clipboard, switch view to plain text mode 

    //end of .ui file

    the error message for this piece of code:
    expected unqualified-id before ‘<‘ token (line 1 )
    expected unqualified-id before ‘<‘ token (line 16)
    expected unqualified-id before ‘!’ token (line 25)
    Multiple markers at this line (refering to line 26)
    — expected constructor, destructor, or type conversion before ‘>’ token
    — ‘style’ does not name a type
    — ‘meta’ does not name a type
    Multiple markers at this line (refering to line 28)
    — ‘body’ does not name a type
    — expected unqualified-id before ‘/’ token
    — expected constructor, destructor, or type conversion before ‘;’ token
    Multiple markers at this line (refering to line 29)
    — ‘p’ does not name a type
    — expected unqualified-id before ‘/’ token

    My question:
    What I don’t understand is, why is it giving an error on line 1 for no apparent reason? It doesn’t give me that error on the other .ui files.
    And why does it seem that it doesn’t recognize html-code in the html part.
    Does anybody have some clue at what is the problem here?

    Edit: posted the .h and .cpp file now

    the .h file:

    1. #ifndef FORMOUTPUT_H_

    2. #define FORMOUTPUT_H_

    3. #include "FormOutput.ui"

    4. class FormOutput : public QWidget, public Ui_FormOutput

    5. {

    6. Q_OBJECT

    7. public:

    8. FormOutput(QWidget* parent = 0, Qt::WFlags flags = 0);

    9. virtual ~FormOutput();

    10. public slots:

    11. void appendError(QString message);

    12. void appendMessage(QString message);

    13. void appendDebugMessage(QString message);

    14. void appendCommand(QString message);

    15. private:

    16. void addTextAtTop(QString message);

    17. };

    18. }

    19. #endif

    To copy to clipboard, switch view to plain text mode 

    the .cpp file:

    #include «FormOutput.h»

    1. FormOutput::FormOutput(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QWidget(parent, flags)

    2. {

    3. setupUi(this);

    4. }

    5. FormOutput::~FormOutput()

    6. {

    7. }

    8. void FormOutput::addTextAtTop(QString message)

    9. {

    10. QTextCursor cursor = this->textBrowser->textCursor();

    11. cursor.insertHtml(message + "<br />");

    12. }

    13. void FormOutput::appendMessage(QString message)

    14. {

    15. this->addTextAtTop(".. " + message);

    16. }

    17. void FormOutput::appendDebugMessage(QString message)

    18. {

    19. this->addTextAtTop("<font color=\"grey\"># " + message +"</font>");

    20. }

    21. void FormOutput::appendCommand(QString message)

    22. {

    23. this->addTextAtTop("<font color=\"green\">-> " + message +"</font>");

    24. }

    25. void FormOutput::appendError(QString message)

    26. {

    27. this->addTextAtTop("<font color=\"red\">-> <b>" + message +"</b></font>");

    28. }

    29. }

    To copy to clipboard, switch view to plain text mode 

    Last edited by jpn; 17th February 2009 at 14:13.

    Reason: missing [code] tags


  2. 17th February 2009, 13:08


    #2

    Default Re: weird error: expected unqualified-id before ‘…’ token

    What exactly are you doing with that file? What returns those errors? It seems you are trying to feed a C++ compiler (or preprocessor) with an XML file.


  3. 17th February 2009, 13:15


    #3

    Default Re: weird error: expected unqualified-id before ‘…’ token

    Quote Originally Posted by wysota
    View Post

    What exactly are you doing with that file? What returns those errors? It seems you are trying to feed a C++ compiler (or preprocessor) with an XML file.

    It’s used to give the user some output that the program gives. Kinda like a logger.


  4. 17th February 2009, 13:45


    #4

    Default Re: weird error: expected unqualified-id before ‘…’ token

    You are including the ui file directly in your cpp program.


  5. 17th February 2009, 14:16


    #5

    Default Re: weird error: expected unqualified-id before ‘…’ token

    How does the .pro file look like? Are you using FORMS variable as suggested in the Qt Designer manual?

    J-P Nurmi


  6. 17th February 2009, 14:18


    #6

    Default Re: weird error: expected unqualified-id before ‘…’ token

    Quote Originally Posted by wysota
    View Post

    You are including the ui file directly in your cpp program.

    thanks, I forgot that.
    But it seems I’m not out of the woods yet….
    I’ll see if I can fix it first.


Syntax in C++ plays a vital role and even with a slight mistake, it can give birth to a lot of unexpected errors. One of these errors is the “expected unqualified id error” that can arise due to some common oversights while writing your code. In this article, we are going to dive deep into the expected unqualified id error and what can be its possible solutions.

What is an Expected Unqualified Id Error?

The Expected Unqualified Id error is one of the most commonly encountered errors in C++ programming. It is an error that occurs when the code which is written does not match the standards and rules of the programming language.

Why does an Expected Unqualified Id error occur?

The expected unqualified id error mainly occurs due to mistakes in the syntax of our C++ code. Some of the most common reasons for this error are as follows:

  1. Omitted or Misplaced Semicolons
  2. Writing Strings without Quotes
  3. Header Files Not Included
  4. Invalid Variable Declaration
  5. Under or Over-usage of Braces

1. Omitted or Misplaced Semicolons

This type of error is very typical and may arise when we place the semicolon in the wrong place or if our code misses a semicolon.

Example:

C++

#include <iostream>

using namespace std;

class teacher;

{

private:

    string num;

public:

    void setNum(int num1) { num = num1; }

    string getNum() { return num }

};

int main() { return 0; }

Output

error: expected unqualified-id before '{' token
    4 | class teacher;{
      |

The above code produced an error. You will notice that the class ‘teacher’ has a semi-colon and the ‘return num’ statement does not. To solve the error you need to remove the semi-colon from the ‘teacher’ class and add a semi-colon at the end of the ‘return’ statement.

2. Writing string values without quotes

Another common mistake that you can make is specifying the values of the string without quotes. C++ does not accept the string value without quotes and interprets it as a variable and throws the ‘expected unqualified id’ error.

Example:

C++

#include <iostream>

using namespace std;

int main()

{

    cout << please enter your age << endl;

    cin >> age;

}

Output

error: 'please' was not declared in this scope
    7 |     cout << please enter your age << endl;
      |

 We have not enclosed ‘please enter your age’ in quotes which is why this piece of code will produce an error.

3. Header File not Included

C++ has a vast amount of libraries defined inside the header file. To use those libraries, we must first include those header files otherwise an expected unqualified error is encountered.

Example:

C++

int main()

{

    cout << "GFG!";

    return 0;

}

Output

error: 'cout' was not declared in this scope
    3 |     cout << "GFG!";
      |     ^~~~

4. Invalid Variable Declaration

While writing the code, you should be mindful of not declaring your functions with the same keywords which are reserved by the language.

Example:

C++

#include <iostream>

using namespace std;

int main()

{

    int case = 10;

    cout << case;

    return 0;

}

Output

error: expected unqualified-id before 'case'
    8 |     int case = 10; 

In the above example, we used “delete” as our function name which is a reserved keyword. The delete function is an inbuilt function in C++ that is used to deallocate the memory of a class object.

5. Over or Under Usage of Braces

Curly braces in C++ are used to declare various variables and help to determine where the statement begins and where it ends and the scope. The curly braces always come in pairs i.e. opening and closing braces. So if any of them is missing, an error is shown.

Example:

C++

#include <iostream>

using namespace std;

int main()

{

    if (true) {

        cout << "You choose the black color";

    }

    else if (false) {

        cout << "You choose the purple color";

        return 0;

    }

Output

error: expected '}' at end of input
   13 | }
      | ^

In the above example, we missed one brace after the if statement which means that the statement is incomplete and will produce the state error.

How to fix the Expected Unqualified Id Error in C++?

Since all of these errors occur due to incorrect syntax, we can avoid these errors by using the correct syntax in our program. Nowadays, many popular code editors contain plugins to check for syntax errors automatically and highlight them even before compilation so it is easy to find and fix these errors.

We can also keep in mind the following points which are one of the most common reasons for this error:

1. Placing Accurate Semi-colons and Braces

Simply placing semi-colons at the end of the statements according to the standards will help in avoiding this error.

Example:

C++

#include <iostream>

using namespace std;

int main()

{

    int a = 3;

    int b = a % 25;

    cout << b << endl;

    return 0;

}

In the code above, we placed a semi-colon after every declaration which helps the compiler to understand that the statement ends here and your code will run successfully.

2. Valid Variable Declaration

You should not declare a variable name that starts with a numeric character as it is not allowed. Also, keywords cannot be used as variables and the identifiers must be unique in their scope so keeping that in mind while declaring the variables will help in avoiding these types of errors.

Example:

C++

#include <iostream>

using namespace std;

int main()

{

    int abc = 10;

    int def = 5;

    int ijk = abc * def;

    cout << ijk;

    return 0;

}

The above code is an example of how you can declare variables to avoid these types of errors.

Last Updated :
29 Mar, 2023

Like Article

Save Article

c++mingwqtqt5qtgui

Porting my project from Qt4 to Qt5.1, I get this error from a Qt file:

C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtGui\qopenglversionfunctions.h:785: error: expected unqualified-id before ')' token
     void (QOPENGLF_APIENTRYP MemoryBarrier)(GLbitfield barriers);
                                           ^

This is the chain of defines:

#define QOPENGLF_APIENTRYP QOPENGLF_APIENTRY *
#define QOPENGLF_APIENTRY APIENTRY
#define APIENTRY WINAPI
#define WINAPI __stdcall

I noticed that the «MemoryBarrier» token is present in the libQt5OpenGLExtensionsd.a library. Should I include it, even if in the original Qt4 project nothing related to OpenGL was used?

Platform:
Windows 7
MinGW 4.8
Qt 4.8 –> Qt 5.1

Я заметил, что токен «MemoryBarrier» присутствует в Библиотека libQt5OpenGLExtensionsd.a. Должен ли я включать его, даже если в оригинальный проект Qt4 ничего не касался OpenGL?

Нет, это не связано. OpenGLExtension скомпилируется после QtGui.

К сожалению, вы нападаете на то, что в Windows уже установлен MemoryBarrier(), и, следовательно, существует конфликт для этого и того, что есть qt. Для этого вы можете найти официальную документацию Windows:

http://msdn.microsoft.com/en-us/library/windows/apps/ms684208(v=vs.85).aspx

Я только что обсуждал это с Gunnar, разработчиком QtGui, и я планирую отправить изменения в Gerrit для решения вашей проблемы.

Мы использовали что-то подобное в нашем проекте пару лет назад, когда писали потокобезопасные синглтоны на основе QtCore:

#if defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 4    
#define __MEMBARRIER __sync_synchronize();  
#elif defined _MSC_VER && defined _WIN64    
#define __MEMBARRIER MemoryBarrier();   
#else   
#define __MEMBARRIER
#endif

Qt может потребоваться проверить ifdef MINGW/GCC/VERSION и определить значение MemoryBarrier.

EDIT: Это было исправлено примерно полгода назад. Для получения дополнительной информации см. Следующий обзор Gerrit и соответствующий отчет об ошибке:

https://codereview.qt-project.org/#change,68156

и

https://bugreports.qt.io/browse/QTBUG-34080

Итак, обновите до Qt 5.2.0, и он будет работать. В противном случае вы можете попытаться выполнить резервное копирование.

Понравилась статья? Поделить с друзьями:
  • R5apex exe ошибка приложения 0xc000007b
  • Qt5widgets dll ошибка
  • Qt5webenginewidgets dll ошибка как исправить
  • R07 ошибка canon
  • R5apex exe ошибка приложения 0xc000005