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

QString Error

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 5 Posters 9.0k 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.
  • M marvic_39
    2 Dec 2015, 08:24

    @kshegunov

    Where you declare variables?

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 2 Dec 2015, 08:35 last edited by kshegunov 12 Feb 2015, 08:36
    #10

    @marvic_39
    Usually where you use them, in functions or blocks. If you have a global variable then it is declared in the .cpp file, thus you don't get the same symbol in multiple translation units (.o files resulting from compilation). It is safe to put extern declarations in header files, because they do not amount to a variable, but are only information for the compiler (and linker).
    This most certainly is a C++ problem. My suggestion is to read up a bit more on C++ to have a better grasp on where and for what memory is allocated. That being said, without a bit more of code and/or information on the problem you're facing I fear I wouldn't be of much help.

    Here are some resources you could use, if you wish:
    http://www.learncpp.com/cpp-tutorial/13-a-first-look-at-variables-initialization-and-assignment/
    http://www.learncpp.com/cpp-tutorial/41-blocks-compound-statements/
    http://www.learncpp.com/cpp-tutorial/42-global-variables/
    https://en.wikipedia.org/wiki/Call_stack

    Read and abide by the Qt Code of Conduct

    M 1 Reply Last reply 2 Dec 2015, 08:47
    0
    • K kshegunov
      2 Dec 2015, 08:35

      @marvic_39
      Usually where you use them, in functions or blocks. If you have a global variable then it is declared in the .cpp file, thus you don't get the same symbol in multiple translation units (.o files resulting from compilation). It is safe to put extern declarations in header files, because they do not amount to a variable, but are only information for the compiler (and linker).
      This most certainly is a C++ problem. My suggestion is to read up a bit more on C++ to have a better grasp on where and for what memory is allocated. That being said, without a bit more of code and/or information on the problem you're facing I fear I wouldn't be of much help.

      Here are some resources you could use, if you wish:
      http://www.learncpp.com/cpp-tutorial/13-a-first-look-at-variables-initialization-and-assignment/
      http://www.learncpp.com/cpp-tutorial/41-blocks-compound-statements/
      http://www.learncpp.com/cpp-tutorial/42-global-variables/
      https://en.wikipedia.org/wiki/Call_stack

      M Offline
      M Offline
      marvic_39
      wrote on 2 Dec 2015, 08:47 last edited by
      #11

      @kshegunov

      I am aware of C++, It looks good, If you provide a solution, how to solve this single statement. You do not need to be proficient.

      R 1 Reply Last reply 2 Dec 2015, 09:04
      0
      • M marvic_39
        2 Dec 2015, 08:47

        @kshegunov

        I am aware of C++, It looks good, If you provide a solution, how to solve this single statement. You do not need to be proficient.

        R Offline
        R Offline
        Ratzz
        wrote on 2 Dec 2015, 09:04 last edited by
        #12

        @marvic_39
        Might be problem with GCC.Check your Gcc version .

        --Alles ist gut.

        M 1 Reply Last reply 2 Dec 2015, 09:07
        0
        • R Ratzz
          2 Dec 2015, 09:04

          @marvic_39
          Might be problem with GCC.Check your Gcc version .

          M Offline
          M Offline
          marvic_39
          wrote on 2 Dec 2015, 09:07 last edited by
          #13

          @Ratzz

          Other apps and examples are working fine and executing properly.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hskoglund
            wrote on 2 Dec 2015, 09:16 last edited by
            #14

            Hi, just guessing, but if that line is inside a class declaration (not outside) then you'll get that 108 error, for example:

            class MyClass {
            ...
            QString settingsFile("/boot/settings.json");
            ...
            };
            

            you could try

            class MyClass {
            ...
            QString settingsFile = "/boot/settings.json";
            ...
            };
            
            M 1 Reply Last reply 2 Dec 2015, 10:03
            0
            • H hskoglund
              2 Dec 2015, 09:16

              Hi, just guessing, but if that line is inside a class declaration (not outside) then you'll get that 108 error, for example:

              class MyClass {
              ...
              QString settingsFile("/boot/settings.json");
              ...
              };
              

              you could try

              class MyClass {
              ...
              QString settingsFile = "/boot/settings.json";
              ...
              };
              
              M Offline
              M Offline
              marvic_39
              wrote on 2 Dec 2015, 10:03 last edited by
              #15

              @hskoglund

              Yes, tried that statement too. Here it's flashing error.

              QString settingsFile = "/neet/one.json";
              
              /home/cpp/cap.h:109: sorry, unimplemented: non-static data member initializers
              
              /home/cpp/cap.h:109: error: in-class initialization of static data member 'str' of non-literal type
              
              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ratzz
                wrote on 2 Dec 2015, 10:07 last edited by
                #16

                @hskoglund
                What is your GCC version ? less than 4.7?

                --Alles ist gut.

                M 2 Replies Last reply 2 Dec 2015, 10:13
                0
                • R Ratzz
                  2 Dec 2015, 10:07

                  @hskoglund
                  What is your GCC version ? less than 4.7?

                  M Offline
                  M Offline
                  marvic_39
                  wrote on 2 Dec 2015, 10:13 last edited by
                  #17

                  @Ratzz

                  gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
                  

                  I cross compiled Linux, OpenCV, FFmpeg Qt Raspi and many other apps never faced a compiler problems.

                  Should this look like compiler version problem?

                  R 1 Reply Last reply 2 Dec 2015, 10:16
                  0
                  • M marvic_39
                    2 Dec 2015, 10:13

                    @Ratzz

                    gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
                    

                    I cross compiled Linux, OpenCV, FFmpeg Qt Raspi and many other apps never faced a compiler problems.

                    Should this look like compiler version problem?

                    R Offline
                    R Offline
                    Ratzz
                    wrote on 2 Dec 2015, 10:16 last edited by Ratzz 12 Feb 2015, 10:18
                    #18

                    @marvic_39 said:
                    But Non static data member initializers available only for GCC >4.7 . Check this . Check the GCC support docs.

                    --Alles ist gut.

                    M 1 Reply Last reply 2 Dec 2015, 10:23
                    1
                    • R Ratzz
                      2 Dec 2015, 10:16

                      @marvic_39 said:
                      But Non static data member initializers available only for GCC >4.7 . Check this . Check the GCC support docs.

                      M Offline
                      M Offline
                      marvic_39
                      wrote on 2 Dec 2015, 10:23 last edited by
                      #19

                      @Ratzz

                      Thank you, Ok, Will check with updated GCC version greater than 4.7.

                      1 Reply Last reply
                      0
                      • R Ratzz
                        2 Dec 2015, 10:07

                        @hskoglund
                        What is your GCC version ? less than 4.7?

                        M Offline
                        M Offline
                        marvic_39
                        wrote on 2 Dec 2015, 11:33 last edited by
                        #20

                        @Ratzz

                        Installed, Still flashing errors.

                        gcc (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04) 4.7.3
                        
                        108   QString settingsFile("Hello");
                        109   QString str="/neet/one.json";
                        
                        /home/cpp/app.h:108: error: expected identifier before string constant
                        /home/cpp/app.h:108: error: expected ',' or '...' before string constant
                        
                        /home//cpp/app.h:109: sorry, unimplemented: non-static data member initializers
                        /home/cpp/app.h:109: error: in-class initialization of static data member 'str' of non-literal type
                        

                        In QT creator it show this, is this correct.

                        Qt Creator 3.5.1 (opensource)
                        Based on Qt 5.5.1 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 32 bit)

                        Built on Oct 13 2015 07:38:32

                        R 1 Reply Last reply 2 Dec 2015, 11:46
                        0
                        • M marvic_39
                          2 Dec 2015, 11:33

                          @Ratzz

                          Installed, Still flashing errors.

                          gcc (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04) 4.7.3
                          
                          108   QString settingsFile("Hello");
                          109   QString str="/neet/one.json";
                          
                          /home/cpp/app.h:108: error: expected identifier before string constant
                          /home/cpp/app.h:108: error: expected ',' or '...' before string constant
                          
                          /home//cpp/app.h:109: sorry, unimplemented: non-static data member initializers
                          /home/cpp/app.h:109: error: in-class initialization of static data member 'str' of non-literal type
                          

                          In QT creator it show this, is this correct.

                          Qt Creator 3.5.1 (opensource)
                          Based on Qt 5.5.1 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 32 bit)

                          Built on Oct 13 2015 07:38:32

                          R Offline
                          R Offline
                          Ratzz
                          wrote on 2 Dec 2015, 11:46 last edited by Ratzz 12 Feb 2015, 11:48
                          #21

                          @marvic_39
                          Are you doing this inside the structure? QString settingsFile("Hello");
                          Is the error at line 108 bec of this ?

                          --Alles ist gut.

                          M 1 Reply Last reply 2 Dec 2015, 11:56
                          0
                          • R Ratzz
                            2 Dec 2015, 11:46

                            @marvic_39
                            Are you doing this inside the structure? QString settingsFile("Hello");
                            Is the error at line 108 bec of this ?

                            M Offline
                            M Offline
                            marvic_39
                            wrote on 2 Dec 2015, 11:56 last edited by marvic_39 12 Feb 2015, 11:56
                            #22

                            @Ratzz

                            I cleaned all GCC versions and activated 4.7
                            Now it's compiled and executed my app.

                            QString settingsFile{"neet/One.json"};
                            

                            Very strange about the brackets () and {}

                            Thank You guys, it's GCC 4.7 made the difference.

                            R 1 Reply Last reply 2 Dec 2015, 12:00
                            0
                            • M marvic_39
                              2 Dec 2015, 11:56

                              @Ratzz

                              I cleaned all GCC versions and activated 4.7
                              Now it's compiled and executed my app.

                              QString settingsFile{"neet/One.json"};
                              

                              Very strange about the brackets () and {}

                              Thank You guys, it's GCC 4.7 made the difference.

                              R Offline
                              R Offline
                              Ratzz
                              wrote on 2 Dec 2015, 12:00 last edited by
                              #23

                              @marvic_39
                              Once your problem is solved please use the Topic Tools button to mark as Solved.
                              Thank you!

                              --Alles ist gut.

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kshegunov
                                Moderators
                                wrote on 2 Dec 2015, 13:34 last edited by
                                #24

                                Ok. I think I get what your problem was. In all probability C++11 is enabled by default in GCC 4.7 (on your distribution), that is why I asked what compiler and environment you're using. Here is the relevant link:
                                http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2756.htm
                                That being said, without the non-static data member initializers supported by the compiler you are obliged to initialize the object in your class' constructor and cannot do it in its declaration. Meaning that if you compile the code on another platform and/or compiler that does not have the C++11 standard enabled you'll get similar errors.

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                0

                                19/24

                                2 Dec 2015, 10:23

                                • Login

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