How disabled few properties for class on one OS
-
Hi everyone!
I'm developing application for few platforms (Desktop and Mobile). My application has a special property in class which supports only one OS (OSX) and I want to disable it for other OS. How I can do it correct? I try this:
#if defined(Q_OS_OSX) Q_PROPERTY(NestleanWebSocketManager* webSocketManager READ getWebSocketManager) #endif
But I receive this errors when I trying build:
tmp/mocs/moc_nestleanrequestmanager.cpp:234:65: error: use of undeclared identifier 'NestleanWebSocketManager' *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< NestleanWebSocketManager* >(); break; ^ tmp/mocs/moc_nestleanrequestmanager.cpp:234:91: error: expected expression *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< NestleanWebSocketManager* >(); break; ^ tmp/mocs/moc_nestleanrequestmanager.cpp:253:36: error: unknown type name 'NestleanWebSocketManager'; did you mean 'NestleanRequestManager'? case 8: *reinterpret_cast< NestleanWebSocketManager**>(_v) = _t->getWebSocketManager(); break; ^~~~~~~~~~~~~~~~~~~~~~~~ NestleanRequestManager tmp/mocs/../../../../NestleanProject/Nestlean/Requests/nestleanrequestmanager.h:28:7: note: 'NestleanRequestManager' declared here class NestleanRequestManager : public QObject ^ tmp/mocs/moc_nestleanrequestmanager.cpp:253:74: error: no member named 'getWebSocketManager' in 'NestleanRequestManager' case 8: *reinterpret_cast< NestleanWebSocketManager**>(_v) = _t->getWebSocketManager(); break; ~~ ^ tmp/mocs/moc_nestlean.cpp:323:65: error: use of undeclared identifier 'NestleanXcodeHelper' *reinterpret_cast<int*>(_a[0]) = qRegisterMetaType< NestleanXcodeHelper* >(); break;
What I do wrong?
Thanks for the any help.
-
Hi,
When are you getting that error ?
-
Hi everyone!
Small updates. Today I've try do this on old version of Qt (5.7 Beta 1). Now I use 5.7 RC1 and the result is:
If I trying build my project on Qt 5.7 Beta 1 all works fine. But if I trying build my application on the Qt 5.7 RC1 I have the problem for this topic. I think this is a bug in MOC system.If someone know how to fix this let me know. Thanks!
-
HI everyone!
I found the problem. I'm using incorrect macros for detect platforms. I'm trying use something like this:
#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) #define NESTLEAN_MOBILE #elif defined(__ANDROID__) #define NESTLEAN_MOBILE #else #define NESTLEAN_DESKTOP #endif
or
#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID) qDebug()<<"MOBILE"; Q_INIT_RESOURCE(resources); #else qDebug()<<"DESKTOP"; Q_INIT_RESOURCE(resources); #endif
Both ways generate errors which I post in my first post. So, question is how I can detect platform if I use mobile (Android and iOS) and Desktop (OS X, Windows, Linux)?
-
Just to be sure I understand correctly: starting with 5.7RC
class MyClass : public QObject { Q_OBJECT #ifdef Q_OS_IOS Q_PROPERTY(QString whatever READ whatever) #endif public: #ifdef Q_OS_IOS QString whatever() const { return "something"}; #endif };
fails to build ?
-
No. I use another macros.
#if defined(Q_OS_OSX) || defined(Q_OS_LINUX) || defined(Q_OS_WIN) //code here #endif
But As I understand the Q_OS_LINUX is defined for Linux and android. And this is my problem.
For now I found solution to use pro file with DEFINES += MOBILE (for mobile) and DEFINES += DESKTOP (for desktop). But as I understand it's not best solution.By the way. On another mac when I have Qt 5.7 Beta1 I also don't install android SDK. And this conditions is works. But If I install SDK for Android it's doesn't work. Maybe I do something wrong.
-
You can use the reverse logic:
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) // mobile stuff #else // desktop stuff #endif
-
I tried this logic (../Helpers/nestleanconstants.h):
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) #define NESTLEAN_MOBILE 1 #else #define NESTLEAN_DESKTOP 1 #endif
And header of class:
#ifndef NESTLEANREQUESTMANAGER_H #define NESTLEANREQUESTMANAGER_H #include <QtCore> #include <QtNetwork> #include "../Helpers/nestleanconstants.h" //Others headers #if defined(NESTLEAN_DESKTOP) #include "WebSocket/nestleanwebsocketmanager.h" #endif class NestleanRequestManager : public QObject { Q_OBJECT Q_CLASSINFO("version", "1.1") Q_PROPERTY(NestleanApplicationRequestsManager* appManager READ getAppManager) //other properties #if defined(NESTLEAN_DESKTOP) Q_PROPERTY(NestleanWebSocketManager* webSocketManager READ getWebSocketManager) #endif private: //some code #if defined(NESTLEAN_DESKTOP) NestleanWebSocketManager* m_webSocketManager; #endif public: //some code #if defined(NESTLEAN_DESKTOP) inline NestleanWebSocketManager* getWebSocketManager() { return m_webSocketManager; } #endif signals: public slots: }; #endif // NESTLEANREQUESTMANAGER_H
Errors the same. I can't understand why it happens.