QSize size(10, 20); // define QSize object with width 10 and height 20 if (size.isValid()) { // do something if the size is valid } else { // do something else if the size is not valid }
QSizeF size(10.5, 20.5); // define QSizeF object with width 10.5 and height 20.5 if (size.toSize().isValid()) { // do something if the size is valid } else { // do something else if the size is not valid }In this example, we create a QSizeF object with a width of 10.5 and a height of 20.5. However, the isValid function only works with QSize objects, not QSizeF objects. To get around this, we convert the QSizeF object to a QSize object using the toSize function, and then call the isValid function on the resulting object. Package library: Qt (QtCore)