Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with foreach loop
Qt 6.11 is out! See what's new in the release blog

Problem with foreach loop

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sri438
    wrote on last edited by
    #1

    hi ..this is my example code i am not getting the output i don't know where i was done the mistake can some one please help me...

    mainwindow.h

    @
    public:
    QGraphicsRectItem *vitem;
    QGraphicsRectItem *hitem;
    @

    mainwindow.cpp
    @
    )//parent items
    vitem = new QGraphicsRectItem(0,0,0,0);
    hitem = new QGraphicsRectItem(0,0,0,0);

    if(i%2==0)
    { //childitems
    new QGraphicsRectItem(0,2,5,20,vitem);
    new QGraphicsRectItem(0,4,5,20,vitem);
    new QGraphicsRectItem(0,6,5,20,vitem);
    new QGraphicsRectItem(0,8,5,20,vitem);
    foreach(QGraphicsItem *item,vitem->childItems())
    {
    foreach(QGraphicsItem *item1,hitem->childItems())
    {
    QRectF rect1 =item->sceneBoundingRect();
    QRectF rect2 =item1->sceneBoundingRect();
    QRectF rect3 =rect1 &rect2;
    qDebug<<rect3<<endl;
    }
    }
    }
    else
    {
    new QGraphicsRectItem(2,0,20,5,hitem);
    new QGraphicsRectItem(4,0,20,5,hitem);
    new QGraphicsRectItem(6,0,20,5,hitem);
    new QGraphicsRectItem(8,0,20,5,hitem);
    foreach(QGraphicsItem *item,hitem->childItems())
    {
    foreach(QGraphicsItem *item1,vitem->childItems())
    {
    QRectF rect1 =item->sceneBoundingRect();
    QRectF rect2 =item1->sceneBoundingRect();
    QRectF rect3 =rect1 & rect2;
    qDebug<<rect3<<endl;
    }
    }
    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Which output do you expect?
      which output do you get?

      The questions you ask are very general, like:

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kxyu
        wrote on last edited by
        #3

        @qDebug()@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved