update
This commit is contained in:
parent
5f85ae0f8f
commit
cf7d33f8b2
@ -854,13 +854,6 @@ int main( int argc, char** argv )
|
||||
|
||||
|
||||
|
||||
ПИШУ ЗДЕСЬ!!!
|
||||
|
||||
|
||||
<<<
|
||||
|
||||
|
||||
|
||||
==== Графическое приложение
|
||||
|
||||
|
||||
@ -875,129 +868,150 @@ int main( int argc, char** argv )
|
||||
git clone --recursive https://git.246060.ru/f1x1t/cmlib-example-app-qt5-gui
|
||||
----
|
||||
|
||||
В файлах `CMakeLists.txt` и `src/cmlib-example/CMakeLists.txt` нужно
|
||||
заменить все строки `cmlib-example-app-qt5-con` на `cmlib-example-app-qt5-gui`.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Для создания минимального графического приложения нужно создать файл
|
||||
описания интерфейса `cmex/src/cmex/my_main_window.ui`:
|
||||
Для графического приложения нужно создать файл описания интерфейса
|
||||
`src/cmlib-example/test_window.ui`:
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MyMainWindow</class>
|
||||
<widget class="QMainWindow" name="MyMainWindow">
|
||||
<class>TestWindow</class>
|
||||
<widget class="QMainWindow" name="TestWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>678</width>
|
||||
<height>415</height>
|
||||
<width>413</width>
|
||||
<height>253</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Main Window</string>
|
||||
<string>Test Window</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="exitButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>170</x>
|
||||
<y>30</y>
|
||||
<width>80</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Press me</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
----
|
||||
|
||||
заголовочный файл `cmex/src/cmex/my_main_window.hpp`:
|
||||
заголовочный файл `src/cmlib-example/test_window.hpp`:
|
||||
|
||||
[source,cpp]
|
||||
----
|
||||
#ifndef CMEX_MY_MAIN_WINDOW_HPP_
|
||||
#define CMEX_MY_MAIN_WINDOW_HPP_
|
||||
#ifndef TEST_WINDOW_HPP_
|
||||
#define TEST_WINDOW_HPP_
|
||||
|
||||
#include <QWidget>
|
||||
#include "ui_my_main_window.h"
|
||||
#pragma once
|
||||
|
||||
class MyMainWindow : public QWidget, private Ui::MyMainWindow {
|
||||
#include "ui_test_window.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class TestWindow : public QMainWindow, private Ui::TestWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MyMainWindow(QWidget* parent = 0);
|
||||
virtual ~MyMainWindow();
|
||||
public:
|
||||
TestWindow(QMainWindow *parent = nullptr);
|
||||
virtual ~TestWindow();
|
||||
};
|
||||
|
||||
#endif /* CMEX_MY_MAIN_WINDOW_HPP_ */
|
||||
#endif /* TEST_WINDOW_HPP_ */
|
||||
----
|
||||
|
||||
и файл с реализацией конструктора и деструктора
|
||||
`cmex/src/cmex/my_main_window.cpp`:
|
||||
и файл с реализацией конструктора, в котором проводится инициализация
|
||||
графических элементов, `src/cmlib-example/test_window.cpp`:
|
||||
|
||||
[source,cpp]
|
||||
----
|
||||
#include "my_main_window.hpp"
|
||||
|
||||
MyMainWindow::MyMainWindow(QWidget* parent) {
|
||||
#include "test_window.hpp"
|
||||
|
||||
TestWindow::TestWindow(QMainWindow* parent) :
|
||||
QMainWindow(parent),
|
||||
Ui::TestWindow()
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
MyMainWindow::~MyMainWindow() {
|
||||
|
||||
}
|
||||
TestWindow::~TestWindow() = default;
|
||||
----
|
||||
|
||||
Для отображения графического окна нужно заменить файл
|
||||
`cmex/src/cmex/main.cpp` на:
|
||||
`src/cmlib-examples/main.cpp` на:
|
||||
|
||||
[source,cpp]
|
||||
----
|
||||
#include "compiler_features.hpp"
|
||||
#include "cmlib_config.hpp"
|
||||
#include "cmlib_private_config.hpp"
|
||||
#include "test_window.hpp"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtWidgets>
|
||||
#include <iostream>
|
||||
#include <cmext/cmext.hpp>
|
||||
#include <myx/qt/translators.hpp>
|
||||
|
||||
#include "cmex.hpp"
|
||||
#include "my_main_window.hpp"
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
||||
QTextStream& qStdOut()
|
||||
namespace MQ = myx::qt;
|
||||
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
static QTextStream ts(stdout);
|
||||
return ts;
|
||||
}
|
||||
QApplication app( argc, argv );
|
||||
qDebug() << QObject::tr( "No" );
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QApplication app(argc, argv);
|
||||
QTranslator translator;
|
||||
// Подключение переводов
|
||||
MQ::QTranslatorsList tl;
|
||||
MQ::append_translators( tl, QStringLiteral( CMLIB_PROJECT_NAME ) );
|
||||
qDebug() << QObject::tr( "Yes" );
|
||||
|
||||
if (translator.load(QLocale(), "cmex_app", QLatin1String("_"), QLatin1String(":/qm")))
|
||||
{
|
||||
app.installTranslator(&translator);
|
||||
}
|
||||
// Установка иконки для программы
|
||||
QApplication::setWindowIcon( QIcon( ":/icon/icon.png" ) );
|
||||
|
||||
// Значение из compiler_features.hpp
|
||||
qStdOut() << QObject::tr("Compiler version: ") << CMEX_COMPILER_VERSION_MAJOR << endl;
|
||||
// Значение из cmlib_config.hpp
|
||||
qStdOut() << QObject::tr("Project version: ") << CMEX_VERSION_STR << endl;
|
||||
// Значение из cmlib_config.hpp
|
||||
qStdOut() << QObject::tr("Build type: ") << BUILD_TYPE << endl;
|
||||
// Функция из внутренней библиотеки
|
||||
qStdOut() << QObject::tr("libcmex function call: ") << cmex_init(4) << endl;
|
||||
// Функция из внешней библиотеки
|
||||
qStdOut() << QObject::tr("libcmext function call: ") << cmext_init(9) << endl;
|
||||
|
||||
MyMainWindow* mmw = new MyMainWindow();
|
||||
mmw->show();
|
||||
return app.exec();
|
||||
// Создание и отображение главного окна
|
||||
auto* w = new TestWindow();
|
||||
w->show();
|
||||
return( QApplication::exec() );
|
||||
}
|
||||
----
|
||||
|
||||
В файле `cmex/src/cmex/CMakeLists.txt` добавить новые файлы к списку
|
||||
|
||||
В файлах `CMakeLists.txt` и `src/cmlib-example/CMakeLists.txt` нужно
|
||||
заменить все строки `cmlib-example-app-qt5-con` на `cmlib-example-app-qt5-gui`.
|
||||
|
||||
Для поиска необходимых компонентов Qt5 нужно в файле `CMakeLists.txt`,
|
||||
находящемся в корневом каталоге проекта, добавить поиск компонентов
|
||||
`Gui` и `Widgets`:
|
||||
|
||||
[source,cmake]
|
||||
----
|
||||
# Используемые компоненты Qt5
|
||||
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
|
||||
----
|
||||
|
||||
|
||||
ПИШУ ЗДЕСЬ!!!
|
||||
|
||||
|
||||
<<<
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
В файле `src/cm/CMakeLists.txt` добавить новые файлы к списку
|
||||
файлов, используемых для компиляции:
|
||||
|
||||
[source,cmake]
|
||||
|
Loading…
x
Reference in New Issue
Block a user