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. MacOs sandbox, security scoped bookmarks
QtWS25 Last Chance

MacOs sandbox, security scoped bookmarks

Scheduled Pinned Locked Moved Unsolved General and Desktop
macosxsandboxbookmarks
4 Posts 4 Posters 1.2k 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.
  • P Offline
    P Offline
    Plamen Petkov
    wrote on 13 Aug 2018, 13:25 last edited by
    #1

    Hi,

    I struggle writing a code related to MacOs security scoped bookmarks (related to MacOs sandboxing, where to keep access to user selected files across App runs one have to facilitate Security Scoped Bookmarks). Anyone having an experience on that matter or point to some links with examples?

    Env: Qt 5.10, MacOs High Sierra

    Plamen

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Aug 2018, 22:13 last edited by
      #2

      Hi and welcome to devnet,

      Try something like:

      QUrl url("file:///Users/your_user/your_file.extension");
      NSURL *nsUrl = url.toNSURL();
      NSError *error = nil;
      NSData *bookmark = [nsUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                                                        includingResourceValuesForKeys:nil
                                                        relativeToURL:nil
                                                        error:&error];
      qDebug() << "Error" << error;
      qDebug() << QByteArray::fromNSData(bookmark);
      

      Hope it helps

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

      Y 1 Reply Last reply 18 Sept 2020, 07:16
      0
      • S SGaist
        13 Aug 2018, 22:13

        Hi and welcome to devnet,

        Try something like:

        QUrl url("file:///Users/your_user/your_file.extension");
        NSURL *nsUrl = url.toNSURL();
        NSError *error = nil;
        NSData *bookmark = [nsUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                                                          includingResourceValuesForKeys:nil
                                                          relativeToURL:nil
                                                          error:&error];
        qDebug() << "Error" << error;
        qDebug() << QByteArray::fromNSData(bookmark);
        

        Hope it helps

        Y Offline
        Y Offline
        YuChao Hsu
        wrote on 18 Sept 2020, 07:16 last edited by
        #3

        @SGaist
        Is this code can compile in *.cpp ?
        I want to add them into my code but occurs some error...

        #if defined(Q_OS_MACOS)
        QUrl url = QUrl::fromLocalFile(selectFolder);
        qInfo() << "Get url: " << url;

        NSURL *nsUrl = url.toNSURL();
        NSError *error = nil; // Unknown type name 'NSError'
        NSData *bookmark = [nsUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                                                          includingResourceValuesForKeys:nil
                                                          relativeToURL:nil
                                                          error:&error];
        // Expected ',' or ']' in lambda capture list
        qDebug() << "Error" << error;
        qDebug() << QByteArray::fromNSData(bookmark);
        

        #endif

        B 1 Reply Last reply 18 Sept 2020, 07:25
        0
        • Y YuChao Hsu
          18 Sept 2020, 07:16

          @SGaist
          Is this code can compile in *.cpp ?
          I want to add them into my code but occurs some error...

          #if defined(Q_OS_MACOS)
          QUrl url = QUrl::fromLocalFile(selectFolder);
          qInfo() << "Get url: " << url;

          NSURL *nsUrl = url.toNSURL();
          NSError *error = nil; // Unknown type name 'NSError'
          NSData *bookmark = [nsUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                                                            includingResourceValuesForKeys:nil
                                                            relativeToURL:nil
                                                            error:&error];
          // Expected ',' or ']' in lambda capture list
          qDebug() << "Error" << error;
          qDebug() << QByteArray::fromNSData(bookmark);
          

          #endif

          B Offline
          B Offline
          Bonnie
          wrote on 18 Sept 2020, 07:25 last edited by
          #4

          @YuChao-Hsu
          That's Objective C++.
          The code need to be in a *.mm file.

          1 Reply Last reply
          1

          • Login

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