qt qxorm qml not supor files .c
-
In another post that I made, they did not give me a solution and I am desperate. The problem is the following: I am making a qml application with qxorm that works correctly. I need to add a subproject that is in its C malloria, but qxorm simply by adding a .c file stops working. The error is that it stops recognizing classes like iostream and others. My question is the following. Should I assume that it is not compatible with C or I am simply doing something wrong?
In this image you can see that without using the .c file it compiles correctly, clarify that it is just a simple project to illustrate the error seen in the previous photos
This is the .pro with the file that causes me an error. clarify that it happened to me with any .c not only with this file. I think that even with the empty file the app stops working
the .pro file
QT += quick CONFIG += c++11 #qxorm ok init include(../QxOrm/QxOrm.pri) TEMPLATE = app DEFINES += _BUILDING_QX_BLOG INCLUDEPATH += ../QxOrm/include/ DESTDIR = $$PWD/_bin/ LIBS += -L"$$PWD/libQxormx32" CONFIG(debug, debug|release) { TARGET = TecnoUnlockerDb LIBS += -l"QxOrmd" } else { TARGET = TecnoUnlockerDb LIBS += -l"QxOrm" } # CONFIG(debug, debug|release) !contains(DEFINES, _QX_NO_PRECOMPILED_HEADER) { PRECOMPILED_HEADER = ./include/precompiled.h } # !contains(DEFINES, _QX_NO_PRECOMPILED_HEADER) #qxorm ok end DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ classproyects/conectmongodb.cpp \ main.cpp \ mi_c_file.c # This file is the one that damages the app RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ classproyects/conectmongodb.h \ include/author.h \ include/export.h
-
@jchaviano Files with .c extension are treated as C language files and are compiled by C compiler.
iostream
is a C++ header and you can't use it in a C file. You have a precompiled header that is included in all your files and it includes <iostream> and bunch of other C++ headers.You have several options to fix this. You could stop using precompiled headers. You could create another library project just for C files. You could remove C++ includes from the precompiled header. Or, the easiest I think, would be to just enclose all C++ headers in the precompiled.h like this:
#ifdef __cplusplus #include <iostream> #include <algorithm> ... the rest of C++ headers #endif
This way your precompiled header will work for both C and C++.
-
This solution gives me other errors.
-
@jchaviano I said enclose all C++ headers, not just standard C++ library headers. Notice that you have Qt headers below that. Qt is a C++ library. You can't use it in C files either. I'm betting everything in that precompiled.h is C++ so you might as well enclose all of it.
By the way - you don't have to include every single Qt header from QtCore (or any other module) individually. You can just
#include <QtCore>
and it will get all of them. -
I stopped using the precompiled headers since the others that you mentioned to me generate more errors.