0

Using Qt Creator 4.10.2 and Qt 5.9/5.12

As described here since C++ 11 you can use the arrow operator in the function's heading. The coding conventions at my place of work currently require for all functions to be written like this.

My problem is that apparently Qt Creator doesn't support this when you auto-generate the definition of a function using refactoring (click on a function in header without definition to open context menu -> select Refactoring -> Add definition to xyz.cpp).

Example: If you have declared a function inside your header

auto foo() -> void;

the auto-generated definition will be

void foo()
{
}

In addition to that apparently the moc generation in Qt doesn't like this style either when used for slots.

Is there a workaround or I just need to make exceptions for all the slots and also always either manually add the definition of a function to my source file or edit the auto-generated one? Perhaps I am missing some tweak in the settings of Qt Creator?

rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
  • Which version of Qt and Qt Creator are you using? – Some programmer dude Feb 11 '20 at 14:22
  • @Someprogrammerdude updated post. Sorry, forgot to add this vital piece of info. – rbaleksandar Feb 11 '20 at 14:26
  • That syntax is mostly meant to work around visibility problems. E.g. `template auto foo(typename std::vector::iterator x) -> decltype(x)`. No reason to use it for something like slot – Swift - Friday Pie Feb 11 '20 at 14:26
  • @Swift-FridayPie Could be. Frankly never used it before (but read what it does here [here](https://en.cppreference.com/w/cpp/language/decltype)) but I have to now. :D – rbaleksandar Feb 11 '20 at 14:29
  • @rbaleksander you're not trying to make template handler? Qt doesn't support that, they barely adapted for lambdas to be connect()-ed. If that's for sake of removing double type declarators, maybe a nested typedef is due – Swift - Friday Pie Feb 11 '20 at 14:34
  • What about Qt Creator's refactoring tool? No support there either? – rbaleksandar Feb 11 '20 at 15:04
  • You have to add CONFIG += c++11 .pro file. Maybe these will help. https://stackoverflow.com/questions/16948382/how-to-enable-c11-in-qt-creator – MrET Feb 13 '20 at 09:53

0 Answers0