I'm just curious. Say, for example, I need to display the number in the console.
The code:
#include <QDebug> #include <QVariant> #include <QString> void displayNumber(quint8 number) { qDebug() << QVariant(number).toString(); qDebug() << QString::number(number); //or for example // QLabel label; // label.setText(QString::number(number)); //or // label.setText(QVariant(number).toString()); }
What would be better? I think the memory consumption is also different. QVariant (number) .toString () means that it stores QVariant on the stack. Not sure about QString :: number (), shouldn't it just call the function (of course, the function returns a QString so that it also gets allocated on the stack and occupies this space and that the operations are allocated and not allocated)? Anyway, sizeof () gives me 16 bytes for QVariant and 4 bytes for QString.
source share