Results 1 to 5 of 5

Thread: foreach error while compiling

  1. #1
    Join Date
    Oct 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default foreach error while compiling

    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

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: foreach error while compiling

    Hi,

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

    Carlos.

  3. #3
    Join Date
    Oct 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: foreach error while compiling

    Hi,

    I am compiling on Windows XP using Visual Studio.

    Manoj

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: foreach error while compiling

    Hi,

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

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

    Carlosl

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: foreach error while compiling

    Quote Originally Posted by smanoj View Post
    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?

Similar Threads

  1. Error compiling vlc
    By arborges in forum Newbie
    Replies: 1
    Last Post: 15th February 2011, 20:26
  2. foreach QTextEdit in Layout
    By slc in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2010, 00:45
  3. lifetime of foreach
    By BalaQT in forum Newbie
    Replies: 4
    Last Post: 4th March 2010, 15:55
  4. Foreach performance
    By jano_alex_es in forum General Programming
    Replies: 2
    Last Post: 17th November 2009, 13:26
  5. Replies: 1
    Last Post: 25th October 2008, 19:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.