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. Convert QString to NSString*

Convert QString to NSString*

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 3.7k 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.
  • B Offline
    B Offline
    BjoernK
    wrote on last edited by
    #1

    Hi all,

    I'm working on an iOS app. I need to convert a QString to a NSString* but I can't figure out how it works. The following code produces a NSException:

    @try
    {
    QString qs = "test";
    NSString* nss = qs.toNSString();
    NSLog(@"qs to ns: %@", [NSString nss]);
    }
    @catch (NSException *theException)
    {
    NSLog(@"An exception occurred: %@", theException.name);
    NSLog(@"Here are some details: %@", theException.reason);
    }

    log output:

    2016-07-25 13:58:13.676 MyApp[3832:1414942] +[NSString nss]: unrecognized selector sent to class 0x3b5b42dc
    2016-07-25 13:58:13.677 MyApp[3832:1414942] An exception occurred: NSInvalidArgumentException
    2016-07-25 13:58:13.677 MyApp[3832:1414942] Here are some details: +[NSString nss]: unrecognized selector sent to class 0x3b5b42dc

    What do I miss?

    Thank you in advance.

    Best regards,
    Björn

    D 1 Reply Last reply
    0
    • D Offline
      D Offline
      DRoscoe
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • B BjoernK

        Hi all,

        I'm working on an iOS app. I need to convert a QString to a NSString* but I can't figure out how it works. The following code produces a NSException:

        @try
        {
        QString qs = "test";
        NSString* nss = qs.toNSString();
        NSLog(@"qs to ns: %@", [NSString nss]);
        }
        @catch (NSException *theException)
        {
        NSLog(@"An exception occurred: %@", theException.name);
        NSLog(@"Here are some details: %@", theException.reason);
        }

        log output:

        2016-07-25 13:58:13.676 MyApp[3832:1414942] +[NSString nss]: unrecognized selector sent to class 0x3b5b42dc
        2016-07-25 13:58:13.677 MyApp[3832:1414942] An exception occurred: NSInvalidArgumentException
        2016-07-25 13:58:13.677 MyApp[3832:1414942] Here are some details: +[NSString nss]: unrecognized selector sent to class 0x3b5b42dc

        What do I miss?

        Thank you in advance.

        D Offline
        D Offline
        DRoscoe
        wrote on last edited by
        #3

        @BjoernK You can probably do it using NSString methods and then filter to QString
        NSString reference

        In particular, look at the "Getting C Strings" portion.

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

          Hi,

          If you want to log nss why not use NSLog(@"qs to ns: %@", nss); ?

          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
          • B Offline
            B Offline
            BjoernK
            wrote on last edited by
            #5

            Thank you for your replies.

            @SGaist you're right - the string conversion is correct but the NSLog() call was wrong.

            I should take a look at the objective C basics.

            Best regards,
            Björn

            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