Solved QString Error
-
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.
-
@marvic_39
Might be problem with GCC.Check your Gcc version . -
Other apps and examples are working fine and executing properly.
-
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"; ... };
-
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
-
@hskoglund
What is your GCC version ? less than 4.7? -
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?
-
@marvic_39 said:
But Non static data member initializers available only for GCC >4.7 . Check this . Check the GCC support docs. -
Thank you, Ok, Will check with updated GCC version greater than 4.7.
-
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
-
@marvic_39
Are you doing this inside the structure? QString settingsFile("Hello");
Is the error at line 108 bec of this ? -
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.
-
@marvic_39
Once your problem is solved please use the Topic Tools button to mark as Solved.
Thank you! -
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.