It turned out that when compiling ui code with C ++ 11, the error "could not find string literal"

I am compiling a QTGUI application (version 4) with my own GNU file. Everything worked well when I used the C ++ 03 standard with the gcc compiler.

Now I need the C ++ 11 standard and get the error:

could not find string operator operator "operator" "__ FILE__"

on the following lines in my window.cpp

connect(ui->myGLWidget, SIGNAL(xRotationChanged(int)), ui->rotXSlider, SLOT(setValue(int)));
connect(ui->myGLWidget, SIGNAL(yRotationChanged(int)), ui->rotYSlider, SLOT(setValue(int)));
connect(ui->myGLWidget, SIGNAL(zRotationChanged(int)), ui->rotZSlider, SLOT(setValue(int)));

      

I tried to compile my .ui file with UIC version 4 and 5 and nothing changed. UIC result ui_window.h has the same errors when Qbject :: connect (.....) is used.

I cannot go back to the old C ++ standard and both UIC compilers generate the same ui_window.h file.

How can I get rid of it?

+3


source to share


1 answer


Before C ++ 11, the syntax "foo"__FILE__

would be compiled as "foo""filename.cpp"

, resulting in the enclosed string being concatenated "foofilename.cpp"

. C ++ 11 added a new custom string literals feature that uses suffixes at the end of a string literal "foo"_bar

to perform string conversion "foo"

to another type. As a consequence, it is "foo"__FILE__

now compiled as an attempt to invoke a custom string literal operator __FILE__

on "foo"

.



Presumably SIGNAL

, and SLOT

both are macros in these sources - I do not know much about the QT - and one or both of their expansion lead to the fact that "foo"__FILE__

there is, after pre-treatment, which leads to an error, which you see. If upgrading to a later QT is not an option for you, you can trace the MACROS definition and make sure there is a gap between the tokens, resulting in "foo"__FILE__

. Plain space insertion may be sufficient, but if macro definitions involve heavy sewing of tokens, then forced unlocking of a token with a comment is sometimes required /**/

.

+10


source







All Articles