0

运行 cmake 时出现以下错误:

C:/Users/Owner/OneDrive/Documents/BJT/src/ui_BJT.h:126:24: error: invalid conversion from 'int' to 'QFont::Weight' [-fpermissive]
         font.setWeight(75);
                        ^~
In file included from C:/Qt/6.1.2/mingw81_64/include/QtWidgets/qwidget.h:49,
                 from C:/Qt/6.1.2/mingw81_64/include/QtWidgets/qabstractbutton.h:48,
                 from C:/Qt/6.1.2/mingw81_64/include/QtWidgets/qcheckbox.h:44,
                 from C:/Qt/6.1.2/mingw81_64/include/QtWidgets/QCheckBox:1,
                 from C:/Users/Owner/OneDrive/Documents/BJT/src/ui_BJT.h:14,
                 from C:\Users\Owner\OneDrive\Documents\BJT\src\ui_BJT.cpp:1:
C:/Qt/6.1.2/mingw81_64/include/QtGui/qfont.h:200:27: note:   initializing argument 1 of 'void QFont::setWeight(QFont::Weight)'
     void setWeight(Weight weight);
                    ~~~~~~~^~~~~~

有问题的代码在这里:

QFont font;
font.setFamily(QStringLiteral("Times New Roman"));
font.setPointSize(16);
font.setBold(true);
font.setWeight(75);
titleLabel->setFont(font);

解决方法是更改​​ font.setWeight(75); 到 font.setWeight(QFont::Weight(75)); 我可以很容易地做到这一点。但是,这是生成的代码,不应更改。这是 Qt Designer 的错误吗?我可以在 Qt Designer 中做些什么来解决这个问题(也许使用样式表)?这在 Qt Designer 的更高版本中修复了吗?

4

0 回答 0