Insert QRectF into QGraphicsRectItem



  • I have created an instance of QRectF and I want it to a parameter of a QGraphicsRectItem but whe I try to pass it as a parameter the compiler says: Program finished unexpectedly. What am I doing wrong?
    QGraphicsRectItem *tempi;

    QList <QRectF> rectan;
    QList <QGraphicsRectItem*>draw_rectan;
    

    for(int i=0;i<random_numbers_.size();i++){
    QRectF temp;
    temp.setRect(i*25,0-random_numbers_[i],20,random_numbers_.at(i));
    rectan.append(temp);
    tempi->setRect(rectan.at(i));
    draw_rectan.append(tempi);

    }
    for(int i=0;i<random_numbers_.size();i++){
        scene->addRect(rectan.at(i),Pen,darkMagentaBrush);
    }

  • Moderators

    @mandruk1331
    most probably because rectan.size() != random_numbers_.size() ?
    Since you are using rectan[i]/rectan.at(i) you need to make sure the index is within bounds.



  • @raven-worx I think that it's the same rectan[i]/rectan.at(i) . I solved the problem,:
    QGraphicsRectItem *tempi = new QGraphicsRectItem;
    tempi->setRect(rectan.at(i));
    draw_rectan.append(tempi);
    I think it was overwriting data


Log in to reply
 

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