first steps
This commit is contained in:
@@ -1,84 +1,23 @@
|
||||
QT += core
|
||||
QT+=core
|
||||
|
||||
TARGET = calc
|
||||
CONFIG+=c++20 console
|
||||
|
||||
VERSION="0.1.0"
|
||||
INCLUDEPATH+="../CalculatorCInterface"
|
||||
|
||||
win32 {
|
||||
BUILD_DATE=$$system("date /t")
|
||||
BUILD_TIME=$$system("time /t")
|
||||
} else {
|
||||
BUILD_DATE=$$system("date +%d-%m-%y")
|
||||
BUILD_TIME=$$system("date +%H:%M:%S")
|
||||
}
|
||||
#LIBS += "C:\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\CalculatorCInterface\debug\libCalculatorCInterface.a"
|
||||
#LIBS += "C:\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\CalculatorCInterface\debug\CalculatorCInterface.dll"
|
||||
|
||||
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
|
||||
|
||||
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
|
||||
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
|
||||
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
|
||||
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
|
||||
|
||||
# keep comments, as /* fall through */
|
||||
QMAKE_CXXFLAGS += -C
|
||||
QMAKE_CXXFLAGS += -g
|
||||
QMAKE_CXXFLAGS += -Wno-deprecated-copy -O
|
||||
|
||||
INCLUDEPATH+=$$_PRO_FILE_PWD_/../CalculatorCInterface/
|
||||
|
||||
LIB_BUILD_DIR="/opt/ptu5/opt/build-ATBTariffCalculator-Desktop_Qt_5_12_12_GCC_64bit-Debug/CalculatorCInterface"
|
||||
|
||||
LIBS += -L$$LIB_BUILD_DIR -lCalculatorCInterface
|
||||
|
||||
|
||||
contains( CONFIG, PTU5 ) {
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
|
||||
CONFIG += link_pkgconfig
|
||||
lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport
|
||||
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
ARCH = PTU5
|
||||
DEFINES+=PTU5
|
||||
}
|
||||
contains( CONFIG, PTU5_YOCTO ) {
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
|
||||
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
PTU5BASEPATH = /opt/devel/ptu5
|
||||
ARCH = PTU5
|
||||
DEFINES+=PTU5
|
||||
|
||||
# add qmqtt lib
|
||||
#LIBS += -lQt5Qmqtt
|
||||
}
|
||||
contains( CONFIG, DesktopLinux ) {
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
|
||||
lessThan(QT_MAJOR_VERSION, 5): CONFIG += extserialport
|
||||
# QMAKE_CC = ccache $$QMAKE_CC
|
||||
# QMAKE_CXX = ccache $$QMAKE_CXX
|
||||
QMAKE_CXXFLAGS += -std=c++17
|
||||
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
|
||||
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
|
||||
ARCH = DesktopLinux
|
||||
DEFINES+=DesktopLinux
|
||||
}
|
||||
# You can make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
main.cpp
|
||||
main.cpp \
|
||||
message_handler.cpp
|
||||
|
||||
# HEADERS += \
|
||||
# tariff_json_template.h \
|
||||
# tariff_editor.h
|
||||
HEADERS += message_handler.h
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# for running program on target through QtCreator
|
||||
contains( CONFIG, PTU5 ) {
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/app/tools/atbupdate/
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
}
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
@@ -1,10 +1,55 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QLibrary>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "message_handler.h"
|
||||
|
||||
#include "calculator_c_interface_lib.h"
|
||||
|
||||
int main() {
|
||||
//#include "tariff_calculator.h"
|
||||
|
||||
qCritical() << "initTariffEditor" << initTariffEditor();
|
||||
typedef TariffCalculator *TariffCalculatorHandle;
|
||||
|
||||
typedef TariffCalculatorHandle (*NewTariffCalculatorFunc)();
|
||||
typedef void (*DeleteTariffCalculatorFunc)(TariffCalculatorHandle handle);
|
||||
|
||||
//extern "C" {
|
||||
//#include "calculator_c_interface_lib.h"
|
||||
//bool __declspec(dllimport) initTariffEditor();
|
||||
//}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
if (!messageHandlerInstalled()) {
|
||||
atbInstallMessageHandler(atbDebugOutput);
|
||||
//setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll");
|
||||
if (library.load()) {
|
||||
qCritical() << "loaded";
|
||||
NewTariffCalculatorFunc f = (NewTariffCalculatorFunc) library.resolve("NewTariffCalculator");
|
||||
TariffCalculatorHandle handle = 0;
|
||||
if (f) {
|
||||
qCritical() << "resolved";
|
||||
handle = f();
|
||||
}
|
||||
DeleteTariffCalculatorFunc d = (DeleteTariffCalculatorFunc) library.resolve("DeleteTariffCalculator");
|
||||
if (d) {
|
||||
qCritical() << "resolved";
|
||||
d(handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//initTariffEditor();
|
||||
|
||||
|
||||
return 0; // a.exec();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
107
Calculator/message_handler.cpp
Normal file
107
Calculator/message_handler.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "message_handler.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <cstring>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageLogContext>
|
||||
|
||||
|
||||
|
||||
#define LOG_EMERG 0
|
||||
#define LOG_ALERT 1
|
||||
#define LOG_CRIT 2
|
||||
#define LOG_ERR 3
|
||||
#define LOG_WARNING 4
|
||||
#define LOG_NOTICE 5
|
||||
#define LOG_INFO 6
|
||||
#define LOG_DEBUG 7
|
||||
|
||||
static char const *DBG_NAME[] = { "DBG ", "WARN ", "CRIT ", "FATAL", "INFO " };
|
||||
static bool installedMsgHandler = false;
|
||||
static int debugLevel = LOG_NOTICE;
|
||||
|
||||
int getDebugLevel() { return debugLevel; }
|
||||
void setDebugLevel(int newDebugLevel) {
|
||||
debugLevel = newDebugLevel;
|
||||
}
|
||||
|
||||
bool messageHandlerInstalled() {
|
||||
return installedMsgHandler;
|
||||
}
|
||||
|
||||
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler) {
|
||||
installedMsgHandler = (handler != 0);
|
||||
static QtMessageHandler prevHandler = nullptr;
|
||||
if (handler) {
|
||||
prevHandler = qInstallMessageHandler(handler);
|
||||
return prevHandler;
|
||||
} else {
|
||||
return qInstallMessageHandler(prevHandler);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief Print message according to given debug level.
|
||||
///
|
||||
/// \note Install this function using qInstallMsgHandler().
|
||||
///
|
||||
/// int main(int argc, char **argv) {
|
||||
/// installMsgHandler(atbDebugOutput);
|
||||
/// QApplication app(argc, argv);
|
||||
/// ...
|
||||
/// return app.exec();
|
||||
/// }
|
||||
///
|
||||
//#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
||||
Q_UNUSED(context);
|
||||
QString const localMsg = QString(DBG_NAME[type]) + msg.toLocal8Bit();
|
||||
|
||||
switch (debugLevel) {
|
||||
case LOG_DEBUG: { // debug-level message
|
||||
fprintf(stderr, "LOG_DEBUG %s\n", localMsg.toStdString().c_str());
|
||||
} break;
|
||||
case LOG_INFO: { // informational message
|
||||
if (type != QtDebugMsg) {
|
||||
fprintf(stderr, "LOG_INFO %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_NOTICE: { // normal, but significant, condition
|
||||
if (type != QtDebugMsg) {
|
||||
fprintf(stderr, "LOG_NOTICE %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_WARNING: { // warning conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg) {
|
||||
fprintf(stderr, "LOG_WARN %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_ERR: { // error conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
fprintf(stderr, "LOG_ERR %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_CRIT: { // critical conditions
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
fprintf(stderr, "LOG_CRIT %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_ALERT: { // action must be taken immediately
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
fprintf(stderr, "LOG_ALERT %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
case LOG_EMERG: { // system is unusable
|
||||
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
|
||||
fprintf(stderr, "LOG_EMERG %s\n", localMsg.toStdString().c_str());
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
//fprintf(stderr, "%s No ErrorLevel defined! %s\n",
|
||||
// datetime.toStdString().c_str(), msg.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
|
23
Calculator/message_handler.h
Normal file
23
Calculator/message_handler.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef MESSAGE_HANDLER_H_INCLUDED
|
||||
#define MESSAGE_HANDLER_H_INCLUDED
|
||||
|
||||
#include <QtGlobal>
|
||||
#ifdef __linux__
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
int getDebugLevel();
|
||||
void setDebugLevel(int newDebugLevel);
|
||||
|
||||
bool messageHandlerInstalled();
|
||||
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler);
|
||||
|
||||
//#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
// typedef void (*QtMessageHandler)(QtMsgType, const char *);
|
||||
//void atbDebugOutput(QtMsgType type, const char *msg);
|
||||
//#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
// typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
|
||||
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
//#endif
|
||||
|
||||
#endif // MESSAGE_HANDLER_H_INCLUDED
|
Reference in New Issue
Block a user