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. Is QSharedMemory supported on Android?
Forum Update on Monday, May 27th 2025

Is QSharedMemory supported on Android?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
10 Posts 3 Posters 1.8k 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.
  • G Offline
    G Offline
    gomgom
    wrote on last edited by gomgom
    #1

    I am working on a mobile app, focusing on Android for now. I'm quite new to C++, Qt QML etc...
    My latest challenge is to create a background service. I have been fighting this for a week, with little success.
    My latest problem is in a test case I'm starting to build. I was hoping to communicate between process and app using QSharedMemory, but have had no luck on Android so far. I simply cannot create a buffer.

    My main.cpp is (trying to reduce it to a minimum for this question):

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QSharedMemory>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      QGuiApplication app(argc, argv);
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      if (engine.rootObjects().isEmpty())
        return -1;
    
      QSharedMemory _sharedMemory("QtMemTest", nullptr);
      if (!_sharedMemory.create(sizeof(int), QSharedMemory::ReadWrite))
        qDebug() << "Failed " << _sharedMemory.errorString();
      else
        qDebug() << "Size " << QString::number(_sharedMemory.size());
    
      return app.exec();
    }
    

    The QML doesn't really matter, it's the hello world template.
    On Windows, I get:
    Size "4096"
    On Android:
    main.cpp:17 (int main(int, char**)): Failed "QSharedMemory::create: unable to lock"

    Forget about communication between processes etc... I only have one process in this example, have tried different keys to no avail.

    This really looks like a basic problem... Do I need a specific Android permission? Is this available in Android?
    I am using Qt Creator 4.6.2, am targeting gcc 4.9, Qt 5.9.6 for Android armv7.

    As a side question, is this the simplest way to communicate between my two processes, knowing one of them is a service?
    Thanks!

    FYI I have tried on Android devices running 6.0 and 8.0.

    G 1 Reply Last reply
    0
    • G gomgom

      @SGaist Hi, thanks for the welcome!

      Thanks also for the lead, I will follow that post and give it a try.

      Out of curiosity, do you know if Qsharedmemory is supposed to work under Android? Asking because I'm struggling a bit with Qt documentation. Qt being such a wide scope project, with already quite many versions behind it, it's hard for a newby to figure out which doc, post, article etc... is still relevant and prevails. So in essence where would you turn to to find this kind of info (short of looking at the code!).
      Thanks.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #6

      @gomgom said in Is QSharedMemory supported on Android?:

      Out of curiosity, do you know if Qsharedmemory is supposed to work under Android?

      Hi,

      As far as I know, QSharedMemory does not work on Android and IOS.

      If you look into the detailed description of QSharedMemory, only Windows and Unix is listed in the description.

      And for those, Windows and Mac in my case, I can confirm they work. Haven‘t worked with QSharedMemory on Linux jet, but they are usually close enough to UNIX-conform that it should work.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • G gomgom

        I am working on a mobile app, focusing on Android for now. I'm quite new to C++, Qt QML etc...
        My latest challenge is to create a background service. I have been fighting this for a week, with little success.
        My latest problem is in a test case I'm starting to build. I was hoping to communicate between process and app using QSharedMemory, but have had no luck on Android so far. I simply cannot create a buffer.

        My main.cpp is (trying to reduce it to a minimum for this question):

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QSharedMemory>
        #include <QDebug>
        
        int main(int argc, char *argv[])
        {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QGuiApplication app(argc, argv);
          QQmlApplicationEngine engine;
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
          if (engine.rootObjects().isEmpty())
            return -1;
        
          QSharedMemory _sharedMemory("QtMemTest", nullptr);
          if (!_sharedMemory.create(sizeof(int), QSharedMemory::ReadWrite))
            qDebug() << "Failed " << _sharedMemory.errorString();
          else
            qDebug() << "Size " << QString::number(_sharedMemory.size());
        
          return app.exec();
        }
        

        The QML doesn't really matter, it's the hello world template.
        On Windows, I get:
        Size "4096"
        On Android:
        main.cpp:17 (int main(int, char**)): Failed "QSharedMemory::create: unable to lock"

        Forget about communication between processes etc... I only have one process in this example, have tried different keys to no avail.

        This really looks like a basic problem... Do I need a specific Android permission? Is this available in Android?
        I am using Qt Creator 4.6.2, am targeting gcc 4.9, Qt 5.9.6 for Android armv7.

        As a side question, is this the simplest way to communicate between my two processes, knowing one of them is a service?
        Thanks!

        FYI I have tried on Android devices running 6.0 and 8.0.

        G Offline
        G Offline
        gomgom
        wrote on last edited by gomgom
        #2

        FYI just tried with Qt 5.11.1, the problem is still there.

        Also, when calling the QSharedMemory functions, I get a series of warnings as follows:

        W libsharedExample.so: (null):0 ((null)): Unimplemented code.
        

        For instance commenting in/out the line with the create call adds/removes 6 such warnings.

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

          Hi and welcome to devnet,

          Depending on what you want to do, intent like described in this blog post might be what you need.

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

          G 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi and welcome to devnet,

            Depending on what you want to do, intent like described in this blog post might be what you need.

            G Offline
            G Offline
            gomgom
            wrote on last edited by
            #4

            @SGaist Hi, thanks for the welcome!

            Thanks also for the lead, I will follow that post and give it a try.

            Out of curiosity, do you know if Qsharedmemory is supposed to work under Android? Asking because I'm struggling a bit with Qt documentation. Qt being such a wide scope project, with already quite many versions behind it, it's hard for a newby to figure out which doc, post, article etc... is still relevant and prevails. So in essence where would you turn to to find this kind of info (short of looking at the code!).
            Thanks.

            G J.HilkJ 2 Replies Last reply
            0
            • G gomgom

              @SGaist Hi, thanks for the welcome!

              Thanks also for the lead, I will follow that post and give it a try.

              Out of curiosity, do you know if Qsharedmemory is supposed to work under Android? Asking because I'm struggling a bit with Qt documentation. Qt being such a wide scope project, with already quite many versions behind it, it's hard for a newby to figure out which doc, post, article etc... is still relevant and prevails. So in essence where would you turn to to find this kind of info (short of looking at the code!).
              Thanks.

              G Offline
              G Offline
              gomgom
              wrote on last edited by
              #5

              @gomgom Another follow up question: I am still trying to figure out what is implemented in Android. I tried another test case today, playing with QSystemSemaphore, and I still get these "unimplemented code" warnings.
              Is there a way to turn functions on and off in Qt? When using pre-built Qt images (not building it yourself), are all features turned on (compiling under Windows)?

              1 Reply Last reply
              0
              • G gomgom

                @SGaist Hi, thanks for the welcome!

                Thanks also for the lead, I will follow that post and give it a try.

                Out of curiosity, do you know if Qsharedmemory is supposed to work under Android? Asking because I'm struggling a bit with Qt documentation. Qt being such a wide scope project, with already quite many versions behind it, it's hard for a newby to figure out which doc, post, article etc... is still relevant and prevails. So in essence where would you turn to to find this kind of info (short of looking at the code!).
                Thanks.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #6

                @gomgom said in Is QSharedMemory supported on Android?:

                Out of curiosity, do you know if Qsharedmemory is supposed to work under Android?

                Hi,

                As far as I know, QSharedMemory does not work on Android and IOS.

                If you look into the detailed description of QSharedMemory, only Windows and Unix is listed in the description.

                And for those, Windows and Mac in my case, I can confirm they work. Haven‘t worked with QSharedMemory on Linux jet, but they are usually close enough to UNIX-conform that it should work.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                3
                • G Offline
                  G Offline
                  gomgom
                  wrote on last edited by
                  #7

                  Thanks for the answers, it indeed looks like the QSharedMemory and QSystemSemaphore classes are not available in Android.
                  I guess I should have trusted the Unimplemented code warnings :-)

                  It would just be good if the Qt class docs were to mention the platform on which each class is implemented! I realize the scope of the work but this could be phased in... In the "since" fields, maybe the supported platforms could be indicated in parenthesis next to the revision number?

                  Anyway, thanks for the answers.

                  J.HilkJ 1 Reply Last reply
                  0
                  • G gomgom

                    Thanks for the answers, it indeed looks like the QSharedMemory and QSystemSemaphore classes are not available in Android.
                    I guess I should have trusted the Unimplemented code warnings :-)

                    It would just be good if the Qt class docs were to mention the platform on which each class is implemented! I realize the scope of the work but this could be phased in... In the "since" fields, maybe the supported platforms could be indicated in parenthesis next to the revision number?

                    Anyway, thanks for the answers.

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by J.Hilk
                    #8

                    @gomgom said in Is QSharedMemory supported on Android?:

                    It would just be good if the Qt class docs were to mention the platform on which each class is implemented! I realize the scope of the work but this could be phased in... In the "since" fields, maybe the supported platforms could be indicated in parenthesis next to the revision number?

                    Well, there is this page:
                    http://doc.qt.io/qt-5/qtmodules.html
                    that targets the Qt Moduls and the platforms they support or don't. It doesn't help in your case, as QSharedMemory is part of the QtCore modul x)


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    G 1 Reply Last reply
                    1
                    • J.HilkJ J.Hilk

                      @gomgom said in Is QSharedMemory supported on Android?:

                      It would just be good if the Qt class docs were to mention the platform on which each class is implemented! I realize the scope of the work but this could be phased in... In the "since" fields, maybe the supported platforms could be indicated in parenthesis next to the revision number?

                      Well, there is this page:
                      http://doc.qt.io/qt-5/qtmodules.html
                      that targets the Qt Moduls and the platforms they support or don't. It doesn't help in your case, as QSharedMemory is part of the QtCore modul x)

                      G Offline
                      G Offline
                      gomgom
                      wrote on last edited by
                      #9

                      @J.Hilk Nice, thanks! It's a good start, I had not paid attention to the platform column on that page.

                      Trying to mark you first post above as the correct answer, but I don't get this option. Is this not like on stackoverflow, doesn't the asker get to pick the correct answer? Right now I only get this option for my own posts.

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

                        Sadly, that's a defect in nodebb.

                        Just in case, classes that are not available on one or more platforms are usually annotated for that like QSharedMemory is. If not, then it's a bug in the documentation.

                        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
                        2

                        • Login

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