Problem with foreach loop



  • 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;
    }
    }
    }
    @



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

    The questions you ask are very general, like:



  • @qDebug()@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.