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. Access to cpp variable from objective c .mm file in qt
Forum Update on Monday, May 27th 2025

Access to cpp variable from objective c .mm file in qt

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 1.4k Views
  • 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.
  • H Offline
    H Offline
    hasti66
    wrote on 11 Oct 2014, 09:06 last edited by
    #1

    I've used a .mm file in my qt creator to implement an ios application. I've declared a cpp method in header file and i've implemented it on .mm file.then in cpp file implementation, i've called an objective-c method for fetching addressbook.

    @
    //.mm file
    @interface MyObject :NSObject
    {
    …
    }
    -(int)doSomethingWith:(void *) aParam;
    @end

    @implementation MyObject

    int MainWindow::MyCPPMethod(void *self, void * aParam)
    {
    self = [[MyObject alloc] init];
    return [(id) self doSomethingWith:aParam];
    }

    -(int)doSomethingWith:(void *) aParam
    {
    NSLog(@“Result: %d” , 21);
    return 21;
    }
    @end

    //
    @

    Everything is right, but i want to use some objective-c variable in cpp side (mainwindow class). how can i share a variable between cpp class and objective-c class in qt?
    Thanks

    [edit: added missing coding tags @ SGaist]

    Hasti Ranjkesh

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Oct 2014, 09:20 last edited by
      #2

      Hi,

      Have a look at the QtMacExtras module. It implements that technique

      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
      • H Offline
        H Offline
        hasti66
        wrote on 11 Oct 2014, 09:36 last edited by
        #3

        Thanks for your help, but i want something like this:

        • fetch contacts names from ios addressbook( with objective-c code in .mm file)
        • save each contact name in an array like QString name[] ( the array is defined in a cpp class)
          how can do that?
          If i define the array in cpp header file, it is not recognized in .mm file.

        Hasti Ranjkesh

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Oct 2014, 22:14 last edited by
          #4

          Don't create an array of QString, just a QStringList, it will make your life easier. Also don't try to share variables like that especially if you are just trying to access some data.

          Follow the code of badgeLabelText in qmacfunctions.h/qmacfunctions_mac.mm

          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

          2/4

          11 Oct 2014, 09:20

          • Login

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