Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How disabled few properties for class on one OS
Forum Updated to NodeBB v4.3 + New Features

How disabled few properties for class on one OS

Scheduled Pinned Locked Moved Unsolved General and Desktop
propertymacrosc++
9 Posts 2 Posters 2.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • shavS Offline
    shavS Offline
    shav
    wrote on last edited by
    #1

    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.

    Mac OS and iOS Developer

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      When are you getting that error ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      shavS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        When are you getting that error ?

        shavS Offline
        shavS Offline
        shav
        wrote on last edited by
        #3

        @SGaist  I'm receiving this error every time when I trying build my application for iOS. I want disable'webSocketManager' property for iOS.

        Mac OS and iOS Developer

        1 Reply Last reply
        0
        • shavS Offline
          shavS Offline
          shav
          wrote on last edited by
          #4

          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!

          Mac OS and iOS Developer

          1 Reply Last reply
          0
          • shavS Offline
            shavS Offline
            shav
            wrote on last edited by
            #5

            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)?

            Mac OS and iOS Developer

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • shavS Offline
                shavS Offline
                shav
                wrote on last edited by shav
                #7

                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.

                Mac OS and iOS Developer

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You can use the reverse logic:

                  #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
                  // mobile stuff
                  #else
                  // desktop stuff
                  #endif
                  

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • shavS Offline
                    shavS Offline
                    shav
                    wrote on last edited by shav
                    #9

                    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.

                    Mac OS and iOS Developer

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved