Hello World "pixelSize is not a member of QFont" (similar w/ "family")
-
I am just starting off learning Qt/Qml/Qt-Quick.
(For reference, I have been a professional software developer for 25+ years, so I'm not a total noob)Installation wasn't uneventful.
I did not know which of packages in the Online Installer to choose.
"Custom" was selected by default, so I went with it.
My first installation I just left the default selected packages, which wasn't very many.
I fired up Qt Creator and it didn't see any "Kits".
I guess that I needed to select at least MSVC or MinGW.
At the time I did not know there was a MaintenanceTool.exe, so I uninstalled and re-installed and selected Qt 5.15.2 MSVC 2019 64-bit and WinGW 64-bit.
I fired up Qt Creator and created a Qt Quick Hello World project.
I made one tiny edit to add a Text and set a font size according to another code guide that I am following that uses Qt 5.14.2:
The auto completion does show there is no pixelSize.
Yet QFont says it does:
https://doc.qt.io/qt-5/qfont.html#setPointSizeIs this some legacy way of setting a font size? 5.14.2 wasn't that long ago, was it?
Am I missing some syntactic sugar?
What is the current way to set font size and family?Odd that even though this gives a red warning (which I take as an error), but the code actually runs! :/
What am I doing wrong?
Thanks!
-
@paulpv said in Hello World "pixelSize is not a member of QFont" (similar w/ "family"):
Odd that even though this gives a red warning (which I take as an error), but the code actually runs! :/
QML is a JavaScript based language, so there is no real compilation, it is a interpreted language
So yes, even if there are errors, as long as this part of code is not executed, all works fine. -
I commonly use Label and often set font size, weight, letterspacing, etc and I tend to write them in a compound fashion;
Label { id: vidx text: "Hello Paul" color: "white" font { bold: true pixelSize: 72 letterSpacing: 2 } anchors,fill: parent
To use Label in QML, you will need to import QtQuick.Controls 2.12 or greater. Notably, Label inherits Text.
-
even if there are errors, as long as this part of code is not executed, all works fine
Yet, one would expect a Qt-specific IDE such as Qt Creator not to have such errors when it doesn't know about documented properties of standard Qt/QML types.
I had a similar issue with some of the
ApplicationWindow
properties in Qt 5.15.2:There are several bugs reported about similar problems (I think I was tracking QTBUG-85888), and the errors I was getting were resolved in later Qt versions, and as I understood this is an issue with Qt itself (
*.qmltypes
), not the Qt Creator.So what you can do is to upgrade to a newer Qt version, but sadly a newer one would be a 6.x (unless you are a commercial customer with access to revisions after 5.15.2, as it is an LTS release), and not everyone can upgrade to 6.x yet.
-
@veryqtperson said in Hello World "pixelSize is not a member of QFont" (similar w/ "family"):
Yet, one would expect a Qt-specific IDE such as Qt Creator not to have such errors when it doesn't know about documented properties of standard Qt/QML types.
It depends on what kind of error you are talking about.
Qt creator has nothing to do with JavaScript Engine used to run the QML code.
What I said, is that even if you QML code is not totally correct, you can run it as long as you are not going through the wrong code part.
This is the way JavaScript / interpreted languages works, so nothing direct link with Qt Creator.But, yes, Qt-Creator is far away from being bug free and the 'M16' error messages are very annoying