PDA

View Full Version : foreach error while compiling



smanoj
23rd November 2011, 13:05
Hi all,

I am new to Qt and wrote a small code which uses foreach, here is the snippet of the code

void GroupBox::setCollapsed(bool collapsed)
{
QObject *o;
foreach (o, children()){
if (o->isWidgetType())
((QWidget *)o)->setVisible(collapsed);
}

setFlat(collapsed);
}

and it is giving me this error while compiling


GroupBox.cpp:40: error: 'foreach' was not declared in this scope

Do we need to include any *.pro to invoke QT Preprocessor as foreach is not a function of C++. Please let me know

- smk

qlands
23rd November 2011, 14:38
Hi,

Which platform are you using? Your code works fine in Linux with gcc (GCC) 4.5.2

Carlos.

smanoj
24th November 2011, 06:07
Hi,

I am compiling on Windows XP using Visual Studio.

Manoj

qlands
24th November 2011, 06:28
Hi,

Take a look at http://msdn.microsoft.com/en-us/library/ms177202%28v=vs.80%29.aspx

It might be that for visual studio is "for each" instead of "foreach"

Carlosl

ChrisW67
24th November 2011, 06:32
GroupBox.cpp:40: error: 'foreach' was not declared in this scope

Do we need to include any *.pro to invoke QT Preprocessor as foreach is not a function of C++. Please let me know
- smk

What are you #include-ing at the top of the file concerned?