1

Get these errors :

C2143: syntax error : missing ',' before ':'  
C2143: syntax error : missing ';' before '{'

Here is code:

 void MainWindow::PrintDir(const QString &str)
    {
        QDir mDir(str);
        QString buffer;
        for(QFileInfo temp :  mDir.entryInfoList()) //first error
        {                                           //second error
            buffer += temp.absoluteFilePath() + "\n";
        }
        ui->textEdit->setText(buffer);
    }

I guess the reason is C++ standard? I try to include him in pro file like this CONFIG += c++11 but nothing happen and still get same errors. Whats wrong?

UPD:
enter image description here

ratojakuf
  • 708
  • 1
  • 11
  • 21

1 Answers1

2

As explained here, it seems like MSVC 2010 doesn't support C++ 11 range-based for loops. This is why you get this error. I recommend you upgrade to MSVC 2012 if you want to use C++11 range-based for loops.

Community
  • 1
  • 1
Iuliu
  • 4,001
  • 19
  • 31
  • 3
    Technically that's the compiler used to build the Qt libs used by Creator. The compiler OP's using to compile his/her snipped may be a totally different one. – peppe Nov 09 '14 at 18:15
  • @peppe I doubt it, the error code he gets is from VS and only 2010 and lower have issues with range-based for (not to mention that linking anything but pure C across Visual Studio versions is asking for trouble in the first place) – PeterT Nov 09 '14 at 18:16
  • @peppe You are right! But considering the complexity level of the error he's getting makes me think that he just installed `Qt 5.3.2 for Windows 32-bit (VS 2010, OpenGL, 539 MB)` from `qt-project.org` which uses the `Qt Creator` compiled with the same version of `Qt` it uses. If this is not true I'm waiting to provide more info but I'm 99% sure this is what happened. – Iuliu Nov 09 '14 at 18:19
  • @PeterT: I'm not saying *"the compiler used cannot possibly be MSVC 2010"* :-) I'm saying that the compiler you see in that dialog may be different from the one OP is using to compile the program. – peppe Nov 09 '14 at 18:21
  • Thx. But now how to include 2012 to Qt? – ratojakuf Nov 10 '14 at 02:35
  • @ratojakuf You need to install `Microsoft Visual Studio 2012` or later and add it to `Qt Creator`'s kits. Or simpler: install `Microsoft Visual Studio 2012` or later and then install `Qt 5.3.2 for Windows 32-bit (VS 2012, OpenGL, 555 MB)` or later from `qt-project.org`. Just beware: if you install `VS 2013` you need to install also the `VS 2013` version of `Qt`. These things have to match. – Iuliu Nov 10 '14 at 07:53
  • I have installed VS 2012 and in Qt Creator's kits add new with msvc 2012 compiler but when i created new project and build it i got this : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' http://i.imgur.com/nFTgJVB.png – ratojakuf Nov 10 '14 at 12:03
  • Try to `Build->Rebuild All`. Possible answers could be found here: http://stackoverflow.com/questions/19575747/error-lnk2038-mismatch-detected-for-msc-ver-value-1600-doesnt-match-valu – Iuliu Nov 10 '14 at 12:15
  • Now work. Just did what you said : >You need to install Microsoft Visual Studio 2012 or later and add it to Qt Creator's kits. Or simpler: install Microsoft Visual Studio 2012 or later and then install Qt 5.3.2 for Windows 32-bit (VS 2012, OpenGL, 555 MB) or later from qt-project.org Thank you again). – ratojakuf Nov 10 '14 at 15:42