Qt, MSVC, Suppress compiler warning in a moc_ - qt

I've just started using MSVC with Qt. While compiling a moc_, MSCV is generating
a warning -
"warning C4251: 'QBasicMutex::d_ptr': class 'QBasicAtomicPointer' needs to have dll-interface to be used by clients of class 'QBasicMutex'
In my own source code I can use :-
#pragma warning ( push )
#pragma warning ( disable : 4251 )
#include <QApplication>
#pragma warning ( pop )
when I include a Qt header, which appears to work, but I can't get it to work with a moc_.
How do I:-
Suppress that warning
Or failing that, turn down the general warning level in MSVC so this warning (and unfortunately any others) are suppressed
I'm using Qt 5.15.2, with MSVC 2019
Thanks.

Add '/wd4251' to your compiler flags (qmake: QMAKE_CXX_FLAGS, cmake: target_compile_definitions)

Related

How do I configure cross-compile toolchain on QtCreator?

I have built a Qt toolchain using Yocto. I installed it and set the environment variables running the script generated by Yocto.
I open QtCreator and configure my cross-compiler kit following these instructions.
I'm unable to build this:
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
hello.show();
return a.exec();
}
Getting this error:
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag'
So I try to build this instead:
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
It's ok. But when I deploy to my target and try to run it can't because it hasn't been compiled for target architecture (arm).
helloworld: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ldd
There is also this warning which could be very indicative:
:-1: warning: "/usr/bin/gcc" is used by qmake, but "/opt/poky/2.1.1/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc" is configured in the kit.
Please update your kit or choose a mkspec for qmake that matches your target environment better.
I tried to set mkspec on my kit configuration but the result it's the same.
Solved. Maybe I "lied" about saying that setting the mkspec manually it wasn't working neither. That's not true, it does. It's just I was having another issues and couldn't test it properly. The problem was mkspec it wasn't the right. It was pointing to linux-g++ and I fixed it pointing to the proper mkspec. Anyway Qt cretator is telling me that he can't find it! so it's that a bug? The first issue (compiling GUI) was solved too thanks to this.

[ERROR]: CallNamedPipe failed. Error=2 (Qt)

I get the following error every time I run my program in Qt-Creator
[ERROR]: CallNamedPipe failed. Error=2
Usually twice: once at startup and again at shutdown.
I found the error is related to QtCreator itself, as running the same compiled program from the console, it do not generate this message.
I also found it is probably related to some configuration or miss-configuration as the installation on my other machine do not produce this behavior.
Related to:
[ERROR]:CallNamedPipe failed. Error=2 (Qt)
Minimal snippet that produce this behavior:
Project:
QT += core
TARGET = test
TEMPLATE = app
SOURCES += main.cpp
Code:
#include <QDebug>
int main(int , char *[])
{
qDebug() << "Hellow world!";
return 0;
}
Is not that it is very annoying, as the software work correctly and the debugger more or less correctly. But that fill the log with those 2 lines again and again.
I tried to install a messageHandler (qInstallMessageHandler()) but the error is printed outside its scope.
Where this message come from? and more important: how to avoid it?
Additional info: I am on Windows (sad). I have the same behavior using G++ and MSVC2013

GLEW and Qt5 redefinition of headers

So,
After upgrading our prject to Qt5 we are experiencing issues with glew. The app links a library that needs glew to work, and that works fine when using the library in non Qt apps.
Now though we are linking the library into a qt app and rendering into a glwidget. This used to work but now it doesnt. We get a huge array of errors that mostly say "redefinition of" something. Here's some examples:
1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition
You get the idea. Anyway how can I stop Qt including its gl stuff so glew can work by itself?
As you can see gles is being a problem, so I was directed to use this:
#define QT_NO_OPENGL_ES_2
But this has no effect at all. There are other errors that don't reference gles like these:
1>c:\glew-1.9.0\include\gl\glew.h(275): error C2371: 'GLdouble' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(71) : see declaration of 'GLdouble'
1>c:\glew-1.9.0\include\gl\glew.h(630): warning C4005: 'GL_DOUBLE' : macro redefinition
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengl.h(68) : see previous definition of 'GL_DOUBLE'
1>c:\glew-1.9.0\include\gl\glew.h(1655): error C2371: 'GLintptr' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(38) : see declaration of 'GLintptr'
1>c:\glew-1.9.0\include\gl\glew.h(1656): error C2371: 'GLsizeiptr' : redefinition; different basic types
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(39) : see declaration of 'GLsizeiptr'
1>c:\glew-1.9.0\include\gl\glew.h(1707): warning C4005: 'GL_BLEND_EQUATION_RGB' : macro redefinition
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\gles2\gl2.h(96) : see previous definition of 'GL_BLEND_EQUATION_RGB'
1>c:\glew-1.9.0\include\gl\glew.h(11533): warning C4005: 'GL_COVERAGE_SAMPLES_NV' : macro redefinition
1> c:\qt\qt5.0.2\5.0.2\msvc2012_64\include\qtgui\qopengles2ext.h(530) : see previous definition of 'GL_COVERAGE_SAMPLES_NV'
Hopefully you can help!
My personal approach with using OpenGL with Qt is to separate all OpenGL related part from Qt class implementation. In the Qt part I then just call into the framework neutral written OpenGL code through regular C or C++ interfaces using standard types. Since the actual OpenGL code makes no references to Qt then, it doesn't have to include Qt headers, avoiding problems like yours.
After a day of screwing around I have a solution!
In order to be cross platform Qt seems to have set OpenGLES to a high priority than desktop openGL.
THe solution to this is to build Qt from source code suing the setting -opengl desktop before you build. Something like this:
configure -debug-and-release -opengl desktop
Then use nmake to build and it works fine!

Qt: Building quazip/zlib Library error

I am statically building the quazip library as mentioned in the following post: linking QuaZip with Qt 4.8.0 into project
I get these error when I build the project:
/QtSDK/QtSources/4.8.0/src/3rdparty/zlib/zconf.h:373:6: error: "_LARGEFILE64_SOURCE" is not defined
In file included from ../../../quazip-0.4.4/quazip/zip.h:56,
from ../../../quazip-0.4.4/quazip/quazip.h:31,
from ../../../quazip-0.4.4/quazip/quazipfile.h:30,
from ../../../quazip-0.4.4/quazip/quazipfile.cpp:24:
/QtSDK/QtSources/4.8.0/src/3rdparty/zlib/zlib.h:1583:32: error: "_FILE_OFFSET_BITS" is not defined
cc1plus: warnings being treated as errors
Are these known errors in zlib library? I am using zlib library in Qt 4.8.0
That would be a bug in your compiler. I can't tell what version of zlib you're using, and your compiler does not show the offending line in the error message, so I can't tell exactly what the line contains. However I suspect that these are lines that have an #if directive with the noted symbol in the expression. Per the C standard, a symbol that is not defined is given a null value (no characters replace it) in an expression in an #if statement. Instead your compiler is erroneously issuing an error.

Qmake build and gcc includes

I am working with Qt and kinda new to it. I want to build a Qt application and created devprog.pro file. However, after executing qmake and make I get the error
c:\qt473\include\qtcore../../src/corelib/global/qglobal.h(45)
: fatal error C10 83: Cannot open
include file: 'stddef.h': No such file
or directory
So I specified the gcc 4.4.1 include location and the error messages (amongst others) I get is:
c:\codeblocks\MinGW\lib\gcc\mingw32\4.4.1\include\stddef.h(211)
: error C2371: ' size_t' :
redefinition; different basic types
predefined C++ types (compiler internal)(19) : see declaration of
'size_ t'
C:\CodeBlocks\MinGW\include\string.h(126)
: error C2143: syntax error : missing
';' before '*'
C:\CodeBlocks\MinGW\include\string.h(126)
: error C4430: missing type specifier
- int assumed. Note: C++ does not support default-int
My question is:
1. How can resolve such error problems as I've scratched my hair off trying to solve this.
2. Is there a way to make automatically let qmake detect your main gcc mingw location without having to set it for each project during qmake execution?

Resources