qt5 example

This commit is contained in:
Alexander Popov 2024-08-11 02:33:53 +03:00
parent 519053708d
commit 12c97ad421
8 changed files with 190 additions and 0 deletions

View File

@ -0,0 +1 @@
../../../code/C++/.clang-format

11
projects/Qt/example/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
# xmake
.xmake/
build/
# qmake
.qmake.stash
*.o
moc_*.cpp
moc_*.j
moc_predefs.h
Makefile

View File

@ -0,0 +1,50 @@
## Темы
### qt5ct
```sh
apt install qt5ct qt5-style-plugins
```
```sh
QT_QPA_PLATFORMTHEME=qt5ct xmake run
```
Настройки осуществляются в приложении `qt5ct`
### Adwaita
Установить пакеты `adwaita-qt` и `adwaita-qt6`.
```sh
apt install adwaita-qt adwaita-qt6
```
Светлая тема
```sh
# Светлая тема
QT_STYLE_OVERRIDE=adwaita xmake run
QT_STYLE_OVERRIDE=Adwaita xmake run
```
Тёмная тема
```sh
# Тёмная тема
QT_STYLE_OVERRIDE=adwaita-dark xmake run
QT_STYLE_OVERRIDE=Adwaita-dark xmake run
```
## Другое
```cpp
/**
* Available platform plugins are:
* eglfs, linuxfb, minimal, minimalegl, offscreen, vnc,
* wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb
*/
qsetenv("QT_QPA_PLATFORM", "minimal").
```

View File

@ -0,0 +1,13 @@
QT += core gui widgets
CONFIG += c++17
INCLUDEPATH += include/ \
SOURCES += src/main.cpp \
src/mainwindow.cpp
HEADERS += \
include/mainwindow.hpp
DESTDIR = build
TARGET = example

View File

@ -0,0 +1,29 @@
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QProcess>
#include <QWidget>
class QPushButton;
class QTextBrowser;
class MainWindow : public QWidget {
Q_OBJECT
Q_CLASSINFO("Author", "Alexander Popov")
Q_CLASSINFO("Status", "Active")
private slots:
void onButtonReleased();
void onCaptureProcessOutput();
private:
QPushButton *button;
QTextBrowser *textBrowser;
QProcess process;
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
};
#endif // MAINWINDOW_HPP

View File

@ -0,0 +1,18 @@
#include <QApplication>
#include <QDebug>
#include <QtWidgets>
#include "mainwindow.hpp"
int main(int argc, char *argv[]) {
// qputenv("QT_STYLE_OVERRIDE", "adwaita-dark");
QApplication app(argc, argv);
MainWindow window;
window.show();
// qDebug() << "Hello World";
return app.exec();
}

View File

@ -0,0 +1,47 @@
#include <QtWidgets>
#include "mainwindow.hpp"
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
setWindowTitle(tr("ololo"));
setGeometry(100, 100, 300, 200);
// widgets
button = new QPushButton(tr("Push Me!"));
textBrowser = new QTextBrowser();
// layout
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(button, 0, 0);
mainLayout->addWidget(textBrowser, 1, 0);
setLayout(mainLayout);
// signals
connect(button, SIGNAL(released()), this, SLOT(onButtonReleased()));
connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(onCaptureProcessOutput()));
}
MainWindow::~MainWindow() {
delete button;
delete textBrowser;
}
void MainWindow::onButtonReleased() {
textBrowser->clear();
textBrowser->append(tr("Running command:\n"));
process.setCurrentWriteChannel(QProcess::StandardOutput);
process.start("ls", QStringList() << "-lh" << qgetenv("HOME"));
// if (!process.waitForStarted() || !process.waitForFinished()) {
// return;
// }
}
void MainWindow::onCaptureProcessOutput() {
QProcess *proc = qobject_cast<QProcess *>(sender());
if (proc) {
textBrowser->append(proc->readAllStandardOutput());
}
}

View File

@ -0,0 +1,21 @@
set_project("example")
add_rules("mode.debug", "mode.release")
if is_mode("debug") then
set_symbols("debug")
set_optimize("none")
end
add_includedirs(
"include" -- APPLICATION
)
add_linkdirs(
)
target("example")
-- set_kind("binary")
add_rules("qt.widgetapp")
add_headerfiles("include/*.hpp")
add_files("src/*.cpp")
-- add files with Q_OBJECT meta (only for qt.moc)
add_files("include/*.hpp")