Qt warning: passing qreal for converting QRect::QRect(int, int, int, int)
Matthew Martinez
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:
QRectF::toRect(discarded decimal part)QRectF::toAlignedRect(rounded).
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:
- QRectF::toRect (rounded to nearest integer)
- QRectF::toAlignedRect (Bounding box, smallest integer rectangle containing the desired QRectF).
toRect
E.g. for precision drawing something that looks accurate
toAlignedRect
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 either0.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.