Skip to content

Commit

Permalink
We need QGuiApplication before accessing to Font Database
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Apr 8, 2024
1 parent 7848e66 commit b4be0cb
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/qt_types_standalone/cpp/qfontmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QtGui/QFont>
#include <QtGui/QFontMetrics>
#include <QtGui/QGuiApplication>
#include <QtTest/QTest>

#include "cxx-qt-gen/qfontmetrics.cxx.h"
Expand All @@ -19,15 +20,33 @@ class QFontMetricsTest : public QObject
private Q_SLOTS:
void construct()
{
std::vector<char*> args;
std::string path = "/path";
args.push_back(path.data());
auto argc = static_cast<int>(args.size());

// QFontDatabase needs a QGuiApplication first
QGuiApplication app(argc, args.data());
app.setApplicationName(QStringLiteral("kdab"));

QFont f;
const int pointSize = 40;
f.setPointSize(40);
f.setPointSize(pointSize);
const auto m = constructor_qfontmetrics(f);
QCOMPARE(m.ascent(), 40);
QCOMPARE(m.height(), 30);
QCOMPARE(m.ascent(), 57);
QCOMPARE(m.height(), 73);
}
void clone()
{
std::vector<char*> args;
std::string path = "/path";
args.push_back(path.data());
auto argc = static_cast<int>(args.size());

// QFontDatabase needs a QGuiApplication first
QGuiApplication app(argc, args.data());
app.setApplicationName(QStringLiteral("kdab"));

QFont f;
f.setBold(true);
f.setPointSize(30);
Expand Down

0 comments on commit b4be0cb

Please sign in to comment.