Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Qt warning: passing qreal for converting QRect::QRect(int, int, int, int)

Writer 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.

3

2 Answers

It appears that rect() returns a QRectF, and you want to convert it to QRect. You have two options:

1

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:

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.