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
52k39 gold badges111 silver badges135 bronze badges
asked Sep 11, 2013 at 11:16
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 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
1,64716 silver badges30 bronze badges
answered Sep 12, 2013 at 7:22
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
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
DevolusDevolus
21.7k13 gold badges66 silver badges113 bronze badges
1
-
17th February 2009, 13:06
#1
weird error: expected unqualified-id before ‘…’ token
The .ui file:
<ui version="4.0" >
<class>FormOutput</class>
<widget class="QWidget" name="FormOutput" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>260</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<property name="styleSheet" >
<string notr="true" >border: 1 solid black;</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QTextBrowser" name="textBrowser" >
<property name="frameShape" >
<enum>QFrame::StyledPanel</enum>
</property>
<property name="html" >
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
<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</p></body></html></string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</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 ‘/’ tokenMy 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:
#ifndef FORMOUTPUT_H_
#define FORMOUTPUT_H_
#include "FormOutput.ui"
class FormOutput : public QWidget, public Ui_FormOutput
{
Q_OBJECT
public:
FormOutput(QWidget* parent = 0, Qt::WFlags flags = 0);
virtual ~FormOutput();
public slots:
void appendError(QString message);
void appendMessage(QString message);
void appendDebugMessage(QString message);
void appendCommand(QString message);
private:
void addTextAtTop(QString message);
};
}
#endif
To copy to clipboard, switch view to plain text mode
the .cpp file:
#include «FormOutput.h»
FormOutput::FormOutput(QWidget* parent /*= 0*/, Qt::WFlags flags /*= 0*/) : QWidget(parent, flags)
{
setupUi(this);
}
FormOutput::~FormOutput()
{
}
void FormOutput::addTextAtTop(QString message)
{
QTextCursor cursor = this->textBrowser->textCursor();
cursor.insertHtml(message + "<br />");
}
void FormOutput::appendMessage(QString message)
{
this->addTextAtTop(".. " + message);
}
void FormOutput::appendDebugMessage(QString message)
{
this->addTextAtTop("<font color=\"grey\"># " + message +"</font>");
}
void FormOutput::appendCommand(QString message)
{
this->addTextAtTop("<font color=\"green\">-> " + message +"</font>");
}
void FormOutput::appendError(QString message)
{
this->addTextAtTop("<font color=\"red\">-> <b>" + message +"</b></font>");
}
}
To copy to clipboard, switch view to plain text mode
Last edited by jpn; 17th February 2009 at 14:13.
Reason: missing [code] tags
-
17th February 2009, 13:08
#2
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.
-
17th February 2009, 13:15
#3
Re: weird error: expected unqualified-id before ‘…’ token
Originally Posted by wysota
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.
-
17th February 2009, 13:45
#4
Re: weird error: expected unqualified-id before ‘…’ token
You are including the ui file directly in your cpp program.
-
17th February 2009, 14:16
#5
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
-
17th February 2009, 14:18
#6
Re: weird error: expected unqualified-id before ‘…’ token
Originally Posted by wysota
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:
- Omitted or Misplaced Semicolons
- Writing Strings without Quotes
- Header Files Not Included
- Invalid Variable Declaration
- 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, и он будет работать. В противном случае вы можете попытаться выполнить резервное копирование.