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. Set NULL QString
Qt 6.11 is out! See what's new in the release blog

Set NULL QString

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 15.9k Views 1 Watching
  • 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.
  • U Offline
    U Offline
    ucomesdag
    wrote on last edited by
    #1

    Just tried to compile some old code and get: error: call of overloaded ‘QString(int)’ is ambiguous

    Maybe I missed something but since when can't we set a null string with @QString snork = 0
    QString snork = NULL@
    Only this seems to work @QString snork = QString()@

    Searched all over but can't find anything about any changes except that QString::null has gone, but never used it.

    Write “Qt”, not “QT” (QuickTime).

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      I think QString wants (const char *) 0 for a Null string.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Or the empty constructor. The API docs has a nice "comparison between null and empty strings":http://doc.qt.nokia.com/4.7/qstring.html#distinction-between-null-and-empty-strings

        0 or NULL is a null pointer, not an object ;-)

        PS:
        In sofar it is sufficient to write

        @
        QString snork;
        @

        as that calls the empty constructor anyways :-)

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • U Offline
          U Offline
          ucomesdag
          wrote on last edited by
          #4

          @Volker I know, but it used to work so nicely :) @QString snork = 0@ is easier to get in a blink of an eye than @QString snork = QString()@

          Write “Qt”, not “QT” (QuickTime).

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            This code compiles and works as expected for me:

            @
            QString snork;
            QString mumin = NULL;
            QString lillemy = 0;

            qDebug();
            qDebug() << "snork:" << snork << snork.isNull() << snork.isEmpty();
            qDebug() << "mumin:" << mumin << mumin.isNull() << mumin.isEmpty();
            qDebug() << "lillemy:" << lillemy << lillemy.isNull() << lillemy.isEmpty();

            // output is
            snork: "" true true
            mumin: "" true true
            lillemy: "" true true
            @

            The source for that constructor (resp. the method that's called) checks for a null pointer and constructs a null QString then.

            BUT
            If I add this to my .pro file the compilation fails:

            @
            DEFINES += QT_NO_CAST_FROM_ASCII
            @

            Maybe you switched the automatic cast from ASCII off?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • U Offline
              U Offline
              ucomesdag
              wrote on last edited by
              #6

              [quote author="Volker" date="1312992977"]
              If I add this to my .pro file the compilation fails:

              @
              DEFINES += QT_NO_CAST_FROM_ASCII
              @

              Maybe you switched the automatic cast from ASCII off?
              [/quote]
              Not that I'm aware, I just created a new Widget Gui Project no DEFINES in it.

              Write “Qt”, not “QT” (QuickTime).

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Hm, strange. Could you check if it is defined at all?

                @
                #if defined(QT_NO_CAST_FROM_ASCII)
                #error "QT_NO_CAST_FROM_ASCII is defined"
                #else
                #error "QT_NO_CAST_FROM_ASCII is NOT defined"
                #endif
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  ucomesdag
                  wrote on last edited by
                  #8

                  I will tomorrow when sober ;-)

                  Write “Qt”, not “QT” (QuickTime).

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    ucomesdag
                    wrote on last edited by
                    #9

                    @Volker: error: #error "QT_NO_CAST_FROM_ASCII is NOT defined"
                    What is your Qt version? Mine is 4.7.3

                    Write “Qt”, not “QT” (QuickTime).

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      ucomesdag
                      wrote on last edited by
                      #10

                      Ok, just replaced all occurrences with QString()
                      And it seems that QString snork = 0 only doesn't work for method declarations.
                      @void doSomething(QString snork1, QString snork2 = 0);@

                      Write “Qt”, not “QT” (QuickTime).

                      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