Qt warning: passing qreal for converting QRect::QRect(int, int, int, int)
Sarah Scott
Updated on March 08, 2026
Qt warning: passing qreal for converting QRect::QRect(int, int, int, int)
I am getting following warnings for code:
QRect rct ( 0, 0, rect().width(), rect().height() ); warning: passing `qreal' for converting 3 of `QRect::QRect(int, int, int, int)' warning: passing `qreal' for converting 4 of `QRect::QRect(int, int, int, int)' I googled it, but haven't found much. How to avoid this warning?
Thanks for you time.
32 Answers
It appears that rect() returns a QRectF, and you want to convert it to QRect. You have two options:
I don't have enough reputation to comment, so I'll have to ammend LogicStuff's reply. Our answers have different interpretation of the documentation so please check for yourselves, and I am happy to delete this if I am wrong.
It appears that rect() returns a QRectF, and you want to convert it to QRect. You have two options:
E.g. for precision drawing something that looks accurate
E.g. for ensuring that you don't omit a line of pixels when drawing something.
For example, 1/3 in binary is 0.0101010101010101010101... so depending on how you calculate one and a half thirds, you may get a half, represented as either 0.10000000000000000... or 0.0111111111111... and maybe round it up calculating one way and down calculating it another. It would then be unfortunate if you drew the edge of a feature (calculated one way) and neglected to erase a row of pixels when wiping the slate clear using a rectangle calculated another way. My calculation example may be wrong, but it's only meant to be illustrative.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoanBtaGmFcn%2BOqqtmr5Gnu6q6xmanmqujnruoedCrnJqkXZu8s3nCqKWvnaKptq%2BzjKqpnpukpr%2Bmr9Oipa1lmaPBbrXNrWSipqQ%3D
Tamela Phillippe
Update: 2023-12-02