migrate: Qt5/C++11 app to Qt6/C++23 with tests and modern Qt APIs
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
Entire-Checkpoint: c1ee98dc34a3
This commit is contained in:
78 files changed
+22627
-1
No files matched your search
@@ -0,0 +1,55 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user