Hello. If I, in QPainter :: DrawText, pass a QString created right among the arguments passed as shown below:

void func(){ for(int i=1; i<=l;i++) qpainter_prt->drawText(1, 1, 1,1, Qt::AlignLeft, QString("%1").arg(i)); } 

Then: Is the QString destructor called immediately after calling the QPainter :: DrawText function? 2 - Is the destructor called after func () ends? 3-if QString destructor is called and the object is destroyed, how will QPainter draw it?

    1 answer 1

    1. Yes, immediately after calling drawText (), the stack argument of QString is called.
    2. No, because it is already destroyed. See the answer to claim 1
    3. Yes, it will, because it uses a copy of the QString object.
    • but how QPainter QPainter will use a copy if a reference is passed to the function as indicated in & in the manual? void QPainter :: drawText (const QPoint & position, const QString & text) - qwe522y
    • The "const QString & text" construction is most likely to indicate that the text will either be copied inside the drawText method, or it will be immediately used. The main thing is that the inviolability of the text argument object is guaranteed, and the only thing that is required of such an argument is the existence during the drawText () call. - vladimir_ki