Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use the .mm file in Qt Project for IOS?
Forum Updated to NodeBB v4.3 + New Features

How to use the .mm file in Qt Project for IOS?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 1.6k Views 1 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.
  • T Offline
    T Offline
    TheCrowKaka
    wrote on 20 Mar 2017, 19:21 last edited by
    #1

    Hello

    I refer to this post regarding getting the UUID on IOS.

    Re: iOS UDID or similar

    I am thoroughly confused on the steps to be taken in order to do this.

    QString UserPreferenceUtility::getMacAddress()
    {
        NSString* mac_address = @"00-00-00-00-00-00-00-01";
        if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
            mac_address = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        }
        return QString::fromNSString(mac_address);
    }
    

    Where am I supposed to put this? Is this to be put in a new .mm file and incorporate in the project or else what?

    I tried to find out how to do that but it seems there is hardly any documentation on this.

    Can someone please elaborate on the exact steps to do this?

    A Qt Enthusiastic...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Schluchti
      wrote on 20 Mar 2017, 19:29 last edited by
      #2

      Just put it in the ios section of your pro file.

      Here you have a sample pro file that contains a *.mm file: https://github.com/gympulsr/qt-pushnotifications/blob/master/qt-pushnotifications.pro

      Want to read more about Qt?

      https://gympulsr.com/blog/qt/

      Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TheCrowKaka
        wrote on 20 Mar 2017, 19:55 last edited by
        #3

        Thanks Schluchti

        That answers the basic question of adding the .mm file to the project.

        But it does not end here... the code given in the refered post is not a complete .mm type code. Please excuse me as i am totally ignorant about the .mm files. But what i do understand is that QString is not a cocoa code but a Qt Code..

        So If I just copy the code from the refered post to a macaddress.mm file, I get two errors

        error: unknown type name 'QString'
        QString UserPreferenceUtility::getMacAddress()
        ^
        and
        error: use of undeclared identifier 'UserPreferenceUtility'
        QString UserPreferenceUtility::getMacAddress()
        ^
        I know I am not doing things the right way... but what is the right way?

        A Qt Enthusiastic...

        S 1 Reply Last reply 20 Mar 2017, 20:29
        0
        • T TheCrowKaka
          20 Mar 2017, 19:55

          Thanks Schluchti

          That answers the basic question of adding the .mm file to the project.

          But it does not end here... the code given in the refered post is not a complete .mm type code. Please excuse me as i am totally ignorant about the .mm files. But what i do understand is that QString is not a cocoa code but a Qt Code..

          So If I just copy the code from the refered post to a macaddress.mm file, I get two errors

          error: unknown type name 'QString'
          QString UserPreferenceUtility::getMacAddress()
          ^
          and
          error: use of undeclared identifier 'UserPreferenceUtility'
          QString UserPreferenceUtility::getMacAddress()
          ^
          I know I am not doing things the right way... but what is the right way?

          S Offline
          S Offline
          Schluchti
          wrote on 20 Mar 2017, 20:29 last edited by Schluchti
          #4

          @TheCrowKaka

          That's probably because you are missing the header file. It should work the following way:

          Create a userpreferenceutility.h file with the following content:

          #ifndef USERPREFERENCEUTILITY_H
          #define USERPREFERENCEUTILITY_H
          
          #include <QObject>
          #include <QString>
          
          class UserPreferenceUtility{
              Q_OBJECT
          public:
              UserPreferenceUtility(QObject* parent = 0);
             ~UserPreferenceUtility();
             QString getMacAddress();
          };
          
          #endif /*USERPREFERENCEUTILITY_H*/
          

          Then add the file to the ios section of your pro file:

          ios{
              HEADERS += $$PWD/path_to_your_file/userpreferenceutility.h \
          }
          

          Next, implement the userpreferenceutility.mm:

          #include "userpreferenceutility.h"
          
          UserPreferenceUtility::UserPreferenceUtility(QObject *parent)
                  : QObject(parent)
           {
           }
          
          QString UserPreferenceUtility::getMacAddress()
          {
              NSString* mac_address = @"00-00-00-00-00-00-00-01";
              if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
                  mac_address = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
              }
              return QString::fromNSString(mac_address);
          }
          
          UserPreferenceUtility::~UserPreferenceUtility(){
          }
          

          And add the file also to the ios section of your pro file. That means you pro file should now look like similar to this:

          ios{
              HEADERS += $$PWD/path_to_your_file/userpreferenceutility.h \
              OBJECTIVE_SOURCES +=   $$PWD/path_to_your_file/userpreferenceutility.h \
          }
          

          Just typed that by heart, so there might be compiling errors ;)

          Want to read more about Qt?

          https://gympulsr.com/blog/qt/

          Latest Article: https://gympulsr.com/blog/qt/2017/06/14/ios-background-music-qt.html

          1 Reply Last reply
          1
          • T Offline
            T Offline
            TheCrowKaka
            wrote on 21 Mar 2017, 16:30 last edited by
            #5

            Thanks

            It works perfect.

            A Qt Enthusiastic...

            1 Reply Last reply
            0

            1/5

            20 Mar 2017, 19:21

            • Login

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