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. how to declare the static QString

how to declare the static QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 4.8k Views 3 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi, I'm using QT5.5 on my computer.
    I declare a static QString like below.

    static QString test_item[9]
        {
            "Touch",
            "Panel",
            "Comport",
            "USB_SD",
            "LAN",
            "CAN",
            "Audio",
            "DIDO",
            "Ignition",
        };
    

    And it will give me an error when i compile it.
    Did i miss anything?
    Please help!

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      You should have posted the error to help us finding the issue.

      In this case, I would say you're missing a = sign between test_items[9] and {.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      6
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        This case is also an excellent example of where you want to use QStringLiteral

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          And I would use a QStringList instead of a C array

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          VRoninV 1 Reply Last reply
          2
          • JKSHJ JKSH

            And I would use a QStringList instead of a C array

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @JKSH said in how to declare the static QString:

            And I would use a QStringList instead of a C array

            I raise you std::array<QString,9>

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            JKSHJ J.HilkJ 2 Replies Last reply
            4
            • VRoninV VRonin

              @JKSH said in how to declare the static QString:

              And I would use a QStringList instead of a C array

              I raise you std::array<QString,9>

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @VRonin said in how to declare the static QString:

              @JKSH said in how to declare the static QString:

              And I would use a QStringList instead of a C array

              I raise you std::array<QString,9>

              That's indeed the best of both worlds

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • VRoninV VRonin

                @JKSH said in how to declare the static QString:

                And I would use a QStringList instead of a C array

                I raise you std::array<QString,9>

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

                @VRonin said in how to declare the static QString:

                @JKSH said in how to declare the static QString:

                And I would use a QStringList instead of a C array

                I raise you std::array<QString,9>

                And I'll answer the problem :-P

                remove the last , thats not supposed to be there

                static QString test_item[9]
                        {
                            "Touch",
                            "Panel",
                            "Comport",
                            "USB_SD",
                            "LAN",
                            "CAN",
                            "Audio",
                            "DIDO",
                            "Ignition"
                        };
                

                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.

                VRoninV 1 Reply Last reply
                4
                • J.HilkJ J.Hilk

                  @VRonin said in how to declare the static QString:

                  @JKSH said in how to declare the static QString:

                  And I would use a QStringList instead of a C array

                  I raise you std::array<QString,9>

                  And I'll answer the problem :-P

                  remove the last , thats not supposed to be there

                  static QString test_item[9]
                          {
                              "Touch",
                              "Panel",
                              "Comport",
                              "USB_SD",
                              "LAN",
                              "CAN",
                              "Audio",
                              "DIDO",
                              "Ignition"
                          };
                  
                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  @J.Hilk Dude! we are discussing philosophy here! go away you and your actually useful solutions! 😆

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  3
                  • E Offline
                    E Offline
                    Eeli K
                    wrote on last edited by
                    #9
                    static QString test_item[9] =
                                {
                                    "Touch",
                                    "Panel",
                                    "Comport",
                                    "USB_SD",
                                    "LAN",
                                    "CAN",
                                    "Audio",
                                    "DIDO",
                                    "Ignition",
                                };
                    

                    works for me as does

                    static QString test_item[]
                            {
                                "Touch",
                                "Panel",
                                "Comport",
                                "USB_SD",
                                "LAN",
                                "CAN",
                                "Audio",
                                "DIDO",
                                "Ignition",
                            };
                    

                    and

                    static QString test_item[] =
                            {
                                "Touch",
                                "Panel",
                                "Comport",
                                "USB_SD",
                                "LAN",
                                "CAN",
                                "Audio",
                                "DIDO",
                                "Ignition",
                            };
                    

                    Might be a compiler thing. I'm using Windows mingw which came with 5.9.

                    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