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
Forum Updated to NodeBB v4.3 + New Features

how to declare the static QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 4.5k 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 12 Jun 2017, 06:37 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
    • J Offline
      J Offline
      JohanSolo
      wrote on 12 Jun 2017, 06:46 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
      • V Offline
        V Offline
        VRonin
        wrote on 12 Jun 2017, 07:13 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
        • J Offline
          J Offline
          JKSH
          Moderators
          wrote on 13 Jun 2017, 09:33 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

          V 1 Reply Last reply 13 Jun 2017, 09:59
          2
          • J JKSH
            13 Jun 2017, 09:33

            And I would use a QStringList instead of a C array

            V Offline
            V Offline
            VRonin
            wrote on 13 Jun 2017, 09:59 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

            J J 2 Replies Last reply 13 Jun 2017, 13:29
            4
            • V VRonin
              13 Jun 2017, 09:59

              @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 Offline
              J Offline
              JKSH
              Moderators
              wrote on 13 Jun 2017, 13:29 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
              • V VRonin
                13 Jun 2017, 09:59

                @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 Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 13 Jun 2017, 13:33 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.

                V 1 Reply Last reply 13 Jun 2017, 13:46
                4
                • J J.Hilk
                  13 Jun 2017, 13:33

                  @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"
                          };
                  
                  V Offline
                  V Offline
                  VRonin
                  wrote on 13 Jun 2017, 13:46 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 13 Jun 2017, 15:09 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

                    1/9

                    12 Jun 2017, 06:37

                    • Login

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