2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2025-01-02 22:47:54 +01:00

Add a demo for qt6

This commit is contained in:
Rafaël Kooi 2024-11-15 21:30:45 +01:00
parent 053e687925
commit 1fb5e0c37c
9 changed files with 254 additions and 0 deletions

32
demos/qt6/but.ui Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>208</width>
<height>113</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="test">
<property name="geometry">
<rect>
<x>40</x>
<y>30</y>
<width>83</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>Hello, world!</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

1
demos/qt6/data/some.txt Normal file
View File

@ -0,0 +1 @@
tada tadam tadadam

38
demos/qt6/foo.cpp Normal file
View File

@ -0,0 +1,38 @@
// Thomas Nagy, 2011-2016
#include "foo.h"
Foo::Foo() : QWidget(NULL) {
m_button = new QPushButton("Foo Button", this);
m_button->setGeometry(QRect(QPoint(50, 60),
QSize(120, 50)));
connect(m_button, SIGNAL (released()), this, SLOT (handleButton()));
myToggle = true;
}
void Foo::handleButton() {
if (myToggle) {
m_button->setText("Button Foo");
} else {
m_button->setText("Foo Button");
}
myToggle = !myToggle;
}
int Foo::FortyTwo() {
return 42;
}
class Bar_private : public QWidget {
Q_OBJECT
signals:
void test();
public:
Bar_private();
};
Bar_private::Bar_private() : QWidget(NULL) {
}
#include "foo.moc"

23
demos/qt6/foo.h Normal file
View File

@ -0,0 +1,23 @@
// Thomas Nagy, 2011-2016
#ifndef _FOO
#define _FOO
#include <QWidget>
#include <QPushButton>
class Foo : public QWidget {
Q_OBJECT
signals:
void test();
private slots:
void handleButton();
public:
Foo();
int FortyTwo();
QPushButton *m_button;
public:
bool myToggle;
};
#endif

4
demos/qt6/linguist/fr.ts Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="1.1" language="fr_FR">
</TS>

27
demos/qt6/main.cpp Normal file
View File

@ -0,0 +1,27 @@
// Thomas Nagy, 2016 (ita)
#include <QApplication>
//#include <QString>
//#include "mainwindow.h"
#include "ui_but.h"
#include "foo.h"
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(res);
QApplication app(argc, argv);
Foo window;
Ui::Form ui;
ui.setupUi(&window);
window.show();
return app.exec();
/*
MainWindow window;
if (argc == 2)
window.openFile(argv[1]);
else
window.openFile(":/files/bubbles.svg");
window.show();
return app.exec();
*/
}

7
demos/qt6/res.qrc Normal file
View File

@ -0,0 +1,7 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file alias="logo.svg">../../docs/slides/presentation/gfx/waflogo.svg</file>
</qresource>
</RCC>

31
demos/qt6/testqt6.cpp Normal file
View File

@ -0,0 +1,31 @@
// Example of Qt6 Unit test with QtTest library
// Federico Pellegrin, 2019 (fedepell)
#include "foo.h"
#include <QtTest/QtTest>
class TestQt6Test: public QObject {
Q_OBJECT
private:
Foo myFoo;
private slots:
void testGui();
void testFunc();
};
// Test of the UI by simulating a button click and button label reading
void TestQt6Test::testGui() {
QCOMPARE(myFoo.m_button->text(), QString("Foo Button"));
QTest::mouseClick(myFoo.m_button, Qt::LeftButton,Qt::NoModifier, QPoint(5,5), 0);
QCOMPARE(myFoo.m_button->text(), QString("Button Foo"));
}
// Test of a normal function
void TestQt6Test::testFunc() {
QCOMPARE(myFoo.FortyTwo(), 44); // this fails! 42 != 44
}
QTEST_MAIN(TestQt6Test)
#include "testqt6.moc"

91
demos/qt6/wscript Normal file
View File

@ -0,0 +1,91 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2016 (ita)
# Federico Pellegrin, 2019 (fedepell)
# Rafaël Kooi, 2024 (RA-Kooi)
VERSION='0.0.1'
APPNAME='qt6_test'
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_cxx qt5 waf_unit_test')
def configure(conf):
conf.want_qt6 = True
#conf.qt6_vars = ['Qt6Core', 'Qt6Gui', 'Qt6Widgets', 'Qt6Test', 'Qt6Svg']
conf.load('compiler_cxx qt5 waf_unit_test')
#conf.env.append_value('CXXFLAGS', ['-g']) # test
if not conf.env.QT_LRELEASE:
# While Qt6 detects most Qt tools, most of them are optional
conf.fatal('lrelease was not found')
# These tests would run on Ubuntu but not on other platforms
conf.check(
define_name = 'XYZ_QT6_TESTS',
mandatory = False,
execute = True,
features = 'qt6 cxx cxxprogram',
includes = '.',
defines = 'QT_WIDGETS_LIB',
use = 'QT6CORE QT6GUI QT6WIDGETS QT6TEST',
msg = 'Checking whether Qt6 tests can run',
fragment = '''
#include <QtTest/QtTest>
class TestQt6Test: public QObject {
Q_OBJECT
private:
void testGui() {
QWidget *widget = NULL;
QTest::mouseClick(widget, Qt::LeftButton, Qt::NoModifier, QPoint(5,5), 0);
}
};
QTEST_MAIN(TestQt6Test)
#include "test.moc"
''')
def build(bld):
# According to the Qt6 documentation:
# Qt classes in foo.h -> declare foo.h as a header to be processed by moc
# add the resulting moc_foo.cpp to the source files
# Qt classes in foo.cpp -> include foo.moc at the end of foo.cpp
#
bld(
features = 'qt6 cxx cxxprogram',
use = 'QT6CORE QT6GUI QT6SVG QT6WIDGETS',
source = 'main.cpp res.qrc but.ui foo.cpp',
moc = 'foo.h',
target = 'window',
includes = '.',
lang = bld.path.ant_glob('linguist/*.ts'),
langname = 'somefile', # include the .qm files from somefile.qrc
)
if bld.env.XYZ_QT6_TESTS:
# Example of integration of Qt6 Unit tests using Qt6Test using waf_unit_test
bld(
features = 'qt6 cxx cxxprogram test',
use = 'QT6CORE QT6GUI QT6WIDGETS QT6TEST',
defines = 'QT_WIDGETS_LIB',
source = 'foo.cpp testqt6.cpp',
moc = 'foo.h',
target = 'footest',
includes = '.',
# ut_str = './${SRC} -o test-report.xml,xunitxml', # put output to a xunit xml
)
bld.add_post_fun(print_test_results) # print output of test runner to user
def print_test_results(bld):
lst = getattr(bld, 'utest_results', [])
if not lst:
return
for result in lst:
print(result.out.decode('utf-8'))
print(result.err.decode('utf-8'))