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. Why is QString(char*) private in trunk?

Why is QString(char*) private in trunk?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.1k 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.
  • M Offline
    M Offline
    Meai
    wrote on last edited by
    #1

    In qstring.h these methods are now private, I checked the qt5 trunk out from git:

    private:
    #if defined(QT_NO_CAST_FROM_ASCII)
    QString &operator+=(const char *s);
    QString &operator+=(const QByteArray &s);
    QString(const char *ch);
    QString(const QByteArray &a);
    QString &operator=(const char *ch);
    QString &operator=(const QByteArray &a);
    #endif

    Why? This is going to make a lot of code uglier, I now have to wrap every single function call where I used to be able to say "string.split("HI")" with "string.split(QString.fromUtf8("HI")"

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

      Hi,

      Look upper in the header file under the "// ASCII compatibility" comment, you'll see that if you don't define QT_NO_CAST_FROM_ASCII the methods are public.

      As for the rest you would rather use:

      @string.split(QLatin1String("Hi"));@

      The reasoning behind is explained in the documentation of QString and QLatin1String

      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
      • hskoglundH Online
        hskoglundH Online
        hskoglund
        wrote on last edited by
        #3

        Hi, also you can use
        @
        string.split(tr("Hi"));
        @

        it's useful in those environments where QString(char*) is private 100% of the time, for example when you're writing a Qt Creator plugin.

        As SGaist suggests, it's a good idea always to put your hardcoded strings inside a function anyway, because maybe your product is a success and you have to translate it to another language!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Meai
          wrote on last edited by
          #4

          There are different approaches to making something multilingual, in any case I would rather have the option of coding as fast as possible and worry about business decisions at a point of time of my choosing.

          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