11

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

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

unable to find string literal operator 'operator"" __ FILE__' "

at 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 the UIC version 4 and 5 and nothing changed. The result of the UIC, ui_window.h has the same errors whenever Qbject::connect(.....) is used.

I can't go back to the old C++ standard and both UIC compilers produces the same ui_window.h file.

How can I get rid of it?

Daniel R.
  • 774
  • 1
  • 7
  • 19
  • 2
    Not enough information. Provide more code and compiler error with line. Also, what version of qt - 4 or 5? We had no any code changes while moving qt4 from `c++03` to `c++11` 3 weeks ago so @Steve I guess you are wrong. In my experience, both qt4 and qt5 projects can be compiled with c++03 and c++11 without source code changes. – VP. May 29 '15 at 13:31
  • @VictorPolevoy My bad, I was thinking of Boost... :) – Steve May 29 '15 at 13:35
  • Does this help? [How to use C++11 with Qt](http://stackoverflow.com/questions/19398438/c-qt-how-to-add-std-c11-to-the-makefile-which-is-generated-by-qmake/19398489#19398489) – TheDarkKnight May 29 '15 at 13:42
  • 1
    @VictorPolevoy Qt 4 does not support `CONFIG += c++11`. See http://stackoverflow.com/a/30031564/2013738 – Simon Warta May 29 '15 at 13:59
  • @SimonWarta I told already - we don't have enough information to answer, thus your point about `qmake` option is excess - who said that `Daniel R.` uses `qmake`? I see here that he uses "his own makefile" so why are you guys talking about qmake? Also, it does not change the fact that both Qt4 and Qt5 can be compiled with c++11 standard. – VP. May 29 '15 at 14:04
  • 2
    Qt Creator is an IDE. Its mention in most SO questions that don't directly refer to the IDE is completely unnecessary and unwarranted. – Kuba hasn't forgotten Monica May 29 '15 at 15:19
  • **What is your compiler? Where is the makefile?** – Kuba hasn't forgotten Monica May 29 '15 at 15:20
  • Maybe also posting the preprocessed file can help. I guess something is wrong with SIGNAL or SLOT. – fassl May 29 '15 at 16:46
  • I am using GNU make with the GCC compiler and Qt4. – Daniel R. May 29 '15 at 19:22
  • uic and moc compiler are also version 4. (What versions exactly i can tell you when i am at my workplace again, then i can edit my question). I only get this error everytime when _connect(..)_ is called compiling with c++11. It is in window.cpp and window.ui – Daniel R. May 29 '15 at 19:28

1 Answers1

19

Before C++11, the syntax "foo"__FILE__ would compile as "foo""filename.cpp", resulting in the concatenated string "foofilename.cpp". C++11 added a new feature, user-defined string literals, that uses suffixes at the end of a string literal "foo"_bar to perform a conversion of the string "foo" to some other type. As a consequence, "foo"__FILE__ now compiles as an attempt to invoke the user-defined string literal operator __FILE__ on "foo".

Presumably SIGNAL and SLOT are both macros on the source lines indicated - I know little about QT - and one or both of their expansions result in "foo"__FILE__ being present after preprocessing, resulting in the error you observe. If upgrading to a more recent QT is not an option for you, you could trace the definition of the MACROS and ensure there is a space between the tokens resulting in the "foo"__FILE__. Simply inserting a space may be sufficient, but if the macro definitions involve heavy token-pasting then sometimes forcing a token break with a comment /**/ is needed.

Casey
  • 41,449
  • 7
  • 95
  • 125
  • 1
    That was exactly my issue. I would like to add that I simply redefined the macros SLOT and LINK in my window.cpp and myglwidget.h with `#define SLOT(a) "1"#a` and `#define SIGNAL(a) "2"#a` – Daniel R. Jun 02 '15 at 14:41
  • 1
    adding a space after my string-format quotes and the macro worked to get rid of `unable to find string literal operator 'operator"" PRIu64'` – nmz787 Feb 17 '21 at 00:57