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,40 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(Qt6MigratedBenchmark LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
add_executable(Qt6MigratedBenchmark
|
||||
main.cpp
|
||||
MainWindow.h
|
||||
MainWindow.cpp
|
||||
MainWindow.ui
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
target_link_libraries(Qt6MigratedBenchmark PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
target_compile_features(Qt6MigratedBenchmark PRIVATE cxx_std_23)
|
||||
|
||||
# Enable warnings
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(Qt6MigratedBenchmark PRIVATE -Wall -Wextra -pedantic)
|
||||
endif()
|
||||
|
||||
# Add tests
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
private slots:
|
||||
void onValidateClicked();
|
||||
void onScreenInfoClicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
QRegularExpression pattern;
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>240</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Qt5 Legacy App</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Initial text</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Enter value like Test123</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="iconLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="validateButton">
|
||||
<property name="text">
|
||||
<string>Validate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="screenButton">
|
||||
<property name="text">
|
||||
<string>Screen Info</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="resultLabel">
|
||||
<property name="text">
|
||||
<string>Result appears here</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
@@ -0,0 +1,19 @@
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
|
||||
#if __has_include(<print>)
|
||||
#include <print>
|
||||
#endif
|
||||
|
||||
[[nodiscard]] auto main(int argc, char* argv[]) -> int
|
||||
{
|
||||
QApplication app{argc, argv};
|
||||
|
||||
// Qt6 uses UTF-8 by default; no codec setup needed
|
||||
MainWindow window;
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>app.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Qt6MigratedBenchmarkTests LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Test)
|
||||
|
||||
add_executable(main_test
|
||||
main_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(main_test PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Test
|
||||
)
|
||||
|
||||
add_test(NAME main_test COMMAND main_test)
|
||||
|
||||
add_executable(MainWindow_test
|
||||
MainWindow_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MainWindow_test PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Test
|
||||
)
|
||||
|
||||
add_test(NAME MainWindow_test COMMAND MainWindow_test)
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <QRect>
|
||||
#include <QRegularExpression>
|
||||
#include <QScreen>
|
||||
#include <QString>
|
||||
#include <QTest>
|
||||
|
||||
class MainWindowPatternTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testPatternValidLettersThenDigits();
|
||||
void testPatternInvalidDigitsThenLetters();
|
||||
void testPatternInvalidSpecialCharacters();
|
||||
void testScreenGeometryExtraction();
|
||||
void testRegularExpressionContainsMethod();
|
||||
};
|
||||
|
||||
void MainWindowPatternTest::testPatternValidLettersThenDigits()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
|
||||
QVERIFY(pattern.match(QString::fromUtf8("Test123")).hasMatch());
|
||||
QVERIFY(pattern.match(QString::fromUtf8("ABC456")).hasMatch());
|
||||
QVERIFY(pattern.match(QString::fromUtf8("a1")).hasMatch());
|
||||
}
|
||||
|
||||
void MainWindowPatternTest::testPatternInvalidDigitsThenLetters()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
|
||||
QVERIFY(!pattern.match(QString::fromUtf8("123Test")).hasMatch());
|
||||
QVERIFY(!pattern.match(QString::fromUtf8("1a")).hasMatch());
|
||||
}
|
||||
|
||||
void MainWindowPatternTest::testPatternInvalidSpecialCharacters()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
|
||||
QVERIFY(!pattern.match(QString::fromUtf8("Test@123")).hasMatch());
|
||||
QVERIFY(!pattern.match(QString::fromUtf8("Test_123")).hasMatch());
|
||||
QVERIFY(!pattern.match(QString::fromUtf8("")).hasMatch());
|
||||
}
|
||||
|
||||
void MainWindowPatternTest::testScreenGeometryExtraction()
|
||||
{
|
||||
const QScreen* screen = QGuiApplication::primaryScreen();
|
||||
if (screen)
|
||||
{
|
||||
const QRect geometry = screen->geometry();
|
||||
QVERIFY(geometry.width() > 0);
|
||||
QVERIFY(geometry.height() > 0);
|
||||
|
||||
const QString info = QString::fromUtf8("Screen: %1x%2").arg(geometry.width()).arg(geometry.height());
|
||||
QVERIFY(!info.isEmpty());
|
||||
QVERIFY(info.contains(QString::fromUtf8("Screen:")));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindowPatternTest::testRegularExpressionContainsMethod()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
|
||||
const QString validInput = QString::fromUtf8("Test123");
|
||||
const QRegularExpressionMatch match = pattern.match(validInput);
|
||||
QVERIFY(match.hasMatch());
|
||||
|
||||
const QString invalidInput = QString::fromUtf8("Invalid");
|
||||
const QRegularExpressionMatch noMatch = pattern.match(invalidInput);
|
||||
QVERIFY(!noMatch.hasMatch());
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainWindowPatternTest)
|
||||
|
||||
#include "MainWindow_test.moc"
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QTest>
|
||||
|
||||
class MainTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testRegularExpressionValidation_data();
|
||||
void testRegularExpressionValidation();
|
||||
void testQStringUtf8Conversion();
|
||||
void testRegularExpressionPattern();
|
||||
};
|
||||
|
||||
void MainTest::testRegularExpressionValidation_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<bool>("expectedMatch");
|
||||
|
||||
QTest::newRow("valid_input_Test123") << QString::fromUtf8("Test123") << true;
|
||||
QTest::newRow("valid_input_ABC456") << QString::fromUtf8("ABC456") << true;
|
||||
QTest::newRow("valid_input_a1") << QString::fromUtf8("a1") << true;
|
||||
QTest::newRow("invalid_input_123Test") << QString::fromUtf8("123Test") << false;
|
||||
QTest::newRow("invalid_input_special") << QString::fromUtf8("Test@123") << false;
|
||||
QTest::newRow("invalid_input_empty") << QString::fromUtf8("") << false;
|
||||
}
|
||||
|
||||
void MainTest::testRegularExpressionValidation()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(bool, expectedMatch);
|
||||
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
const bool matches = pattern.match(input).hasMatch();
|
||||
|
||||
QCOMPARE(matches, expectedMatch);
|
||||
}
|
||||
|
||||
void MainTest::testQStringUtf8Conversion()
|
||||
{
|
||||
const QString title = QString::fromUtf8("Qt6 Migrated Benchmark");
|
||||
QCOMPARE(title, QString::fromUtf8("Qt6 Migrated Benchmark"));
|
||||
|
||||
const QString label = QString::fromUtf8("Bitte Text wie Test123 eingeben.");
|
||||
QCOMPARE(label, QString::fromUtf8("Bitte Text wie Test123 eingeben."));
|
||||
}
|
||||
|
||||
void MainTest::testRegularExpressionPattern()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
QVERIFY(pattern.isValid());
|
||||
|
||||
const QRegularExpressionMatch match = pattern.match(QString::fromUtf8("Test123"));
|
||||
QVERIFY(match.hasMatch());
|
||||
|
||||
const QRegularExpressionMatch noMatch = pattern.match(QString::fromUtf8("123Test"));
|
||||
QVERIFY(!noMatch.hasMatch());
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
|
||||
#include "main_test.moc"
|
||||
Reference in new issue
Block a user