Files
qt-migration-copilot-demo/qt6-after/qt6-migrated-benchmark/MainWindow.cpp
T
torsten 3bdffc8a7f
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
migrate: Qt5/C++11 app to Qt6/C++23 with tests and modern Qt APIs
Entire-Checkpoint: c1ee98dc34a3
2026-08-13 10:18:41 +02:00

55 lines
1.5 KiB
C++

#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QApplication>
#include <QPixmap>
#include <QScreen>
#include <QString>
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow), pattern(QRegularExpression(R"(^[A-Za-z]+\d+$)"))
{
ui->setupUi(this);
// Qt6 uses UTF-8 by default; no codec needed
setWindowTitle(QString::fromUtf8("Qt6 Migrated Benchmark"));
ui->label->setText(QString::fromUtf8("Bitte Text wie Test123 eingeben."));
ui->iconLabel->setPixmap(QPixmap(":/icons/app.png").scaled(48, 48));
// Modern function-pointer connect syntax
connect(ui->validateButton, &QPushButton::clicked, this, &MainWindow::onValidateClicked);
connect(ui->screenButton, &QPushButton::clicked, this, &MainWindow::onScreenInfoClicked);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onValidateClicked()
{
const QString text = ui->lineEdit->text();
if (pattern.match(text).hasMatch())
{
ui->resultLabel->setText(QString::fromUtf8("Match"));
}
else
{
ui->resultLabel->setText(QString::fromUtf8("No match"));
}
}
void MainWindow::onScreenInfoClicked()
{
// Qt6: Use QScreen instead of deprecated QDesktopWidget
const QScreen* screen = QApplication::primaryScreen();
if (screen)
{
const QRect screenGeometry = screen->geometry();
const QString info =
QString::fromUtf8("Screen: %1x%2").arg(screenGeometry.width()).arg(screenGeometry.height());
ui->resultLabel->setText(info);
}
}