Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QString Error

    General and Desktop
    5
    24
    7235
    Loading More Posts
    • 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 last edited by

      Hello,

      What is wrong in this statement, it worked on another machine.

      On my machine ( VMWare) flashing error.

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

      Error Message

      /home/cpp/cap.h:108: error: function definition does not declare parameters
      

      Answers Appreciated.

      1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators last edited by

        Hello,
        This is not a Qt problem, your C++ syntax is wrong. Function arguments (constructors included) are surrounded by parenthesis, not with curly braces.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply Reply Quote 0
        • M
          marvic_39 last edited by marvic_39

          Thank you for replay, i changed to circle brackets

          QString settingsFile("/neet/one.json");
          

          still It flashing error again.

          /home/cpp/cap.h:108: error: expected identifier before string constant
          /home/cpp/cap.h:108: error: expected ',' or '...' before string constant```
          
          Thank You.
          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            @marvic_39 said:
            and you do have
            #include <QString>
            ?

            M 1 Reply Last reply Reply Quote 0
            • M
              marvic_39 @mrjj last edited by

              @mrjj

              Yes, #include <QString>
              As well
              #include <QtCore>

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @marvic_39 last edited by

                @marvic_39
                can it be error from lines above it as

                #include <QString>
                QString settingsFile("/boot/settings.json");
                

                surely compiles.

                check if lines above has ; in the end

                M 1 Reply Last reply Reply Quote 0
                • M
                  marvic_39 @mrjj last edited by marvic_39

                  @mrjj

                  This is the statement, Still errors

                  QString settingsFile("/neet/one.json");
                  
                  

                  And header
                  #include <QString>

                  1 Reply Last reply Reply Quote 0
                  • kshegunov
                    kshegunov Moderators last edited by

                    Ok, the statement is valid. Where is this located, in your header? It's not a good idea to declare variables in headers. Also, how do you compile (what environment/compiler) are you using?

                    Read and abide by the Qt Code of Conduct

                    M 1 Reply Last reply Reply Quote 1
                    • M
                      marvic_39 @kshegunov last edited by

                      @kshegunov

                      Where you declare variables?

                      kshegunov 1 Reply Last reply Reply Quote 0
                      • kshegunov
                        kshegunov Moderators @marvic_39 last edited by kshegunov

                        @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 Reply Quote 0
                        • M
                          marvic_39 @kshegunov last edited by

                          @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.

                          Ratzz 1 Reply Last reply Reply Quote 0
                          • Ratzz
                            Ratzz @marvic_39 last edited by

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

                            --Alles ist gut.

                            M 1 Reply Last reply Reply Quote 0
                            • M
                              marvic_39 @Ratzz last edited by

                              @Ratzz

                              Other apps and examples are working fine and executing properly.

                              1 Reply Last reply Reply Quote 0
                              • hskoglund
                                hskoglund last edited by

                                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 Reply Quote 0
                                • M
                                  marvic_39 @hskoglund last edited by

                                  @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 Reply Quote 0
                                  • Ratzz
                                    Ratzz last edited by

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

                                    --Alles ist gut.

                                    M 2 Replies Last reply Reply Quote 0
                                    • M
                                      marvic_39 @Ratzz last edited by

                                      @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?

                                      Ratzz 1 Reply Last reply Reply Quote 0
                                      • Ratzz
                                        Ratzz @marvic_39 last edited by Ratzz

                                        @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 Reply Quote 1
                                        • M
                                          marvic_39 @Ratzz last edited by

                                          @Ratzz

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

                                          1 Reply Last reply Reply Quote 0
                                          • M
                                            marvic_39 @Ratzz last edited by

                                            @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

                                            Ratzz 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post