2017-11-18 103 views
0

我似乎有问题与qtcreator不自动完成我的代码,这是变得非常讨厌。当使用结构绑定时,qtcreator不自动完成?

目前是不能自动完成,当我尝试在这样的循环使用结构绑定..

std::vector<pair<string,AudioFile<double>>> list_of_files; 
// Some init of list_of_file 


for (const auto& [name,file]: this->list_of_files) // red line under this.. does seem to like structure bindings? 
{ 
    file.printSummary(); // qtcreator don't offer any autocomplete options? 

} 

qtcreator基本上抱怨大约上面贴的代码一切..

但是,当我这样写:

for (int i = 0 ; i <list_of_file.size() ; i++) // No red lines under this.. 
{ 
    list_of_files[i].second.printSummary() // Autocompletes without any problems. 
} 

qtcreator不会抱怨这个代码,似乎自动完成它就好了。那么为什么会造成这么多的问题毫秒与C + + 17风格?

对此有任何修复?

+0

难道只有QtCreator *编辑*它抱怨?或者你在建造时遇到错误?如果是前者,那么可能是因为编辑器尚未更新(或者您使用的是旧版本)。如果是后者,那么你的编译器不支持C++ 17,你可能需要明确地启用它。 –

+0

你使用Qt自己的代码模型还是叮当代码模型?您可以检入工具 - >选项 - > C++ - >代码模型。尽管从技术上讲它并不重要,因为它们都不支持C++ 17。 – nwp

+0

@Someprogrammerdude我还没有尝试过其他编辑器,并且我最近将qtcreator升级到最新版本5.9.2。代码编译,没有错误。在两个循环中都应该如此。 – Lamda

回答

0

这样做的一个临时解决方案似乎是这样的 - 它的自动填充不抱怨,而且似乎适合我的定义(可读性):

for (const auto &elements : this->list_of_files) 
{ 
    auto name = std::get<0>(elements); 
    auto file = std::get<1>(elements); 
} 
相关问题