Mercurial > public > ostc_companion
changeset 2:177f640940f2
Update exception class and cleanup redifinitions
During firmware download and exception caused the application to stop.
Rootcause was the defference between QT5 and QT6 exception and string
handling which is updated now. In addition some old definitions were
removed to avoid compiler warnings.
| author | Ideenmodellierer |
|---|---|
| date | Fri, 28 Nov 2025 19:57:35 +0100 |
| parents | 0b3630a29ad8 |
| children | 4ace58a7c03c |
| files | Serial.cpp Utils/Exception.cpp Utils/Exception.h main.cpp |
| diffstat | 4 files changed, 29 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Serial.cpp Thu Nov 27 18:40:28 2025 +0100 +++ b/Serial.cpp Fri Nov 28 19:57:35 2025 +0100 @@ -231,11 +231,9 @@ S_LEN len = 0; S_READ(_hSerial, &byte, 1, len); if( len != 1 ) - // LOG_THROW_E(ReadTimeout, "< timeout" ); - LOG_THROW("< timeout" ); + LOG_THROW_E(ReadTimeout, "< timeout" ); if( isprint(byte) ) - // LOG_DEBUG("< " << QString().sprintf("%02x '%c'", byte, byte) ); LOG_DEBUG("< " << QString::asprintf("%02x '%c'", byte, byte)); else LOG_DEBUG("< " << QString::asprintf("%02x", byte) );
--- a/Utils/Exception.cpp Thu Nov 27 18:40:28 2025 +0100 +++ b/Utils/Exception.cpp Fri Nov 28 19:57:35 2025 +0100 @@ -37,6 +37,18 @@ #include <QString> + +Exception::Exception(const QString& msg) + : _msg(msg.toStdString()) {} + +Exception::Exception(const char* msg) + : _msg(msg) {} + +const char* Exception::what() const noexcept { + return _msg.c_str(); +} + +#if 0 Exception::Exception(const char* msg) : _msg(strdup(msg)) {} @@ -54,3 +66,4 @@ { return _msg; } +#endif
--- a/Utils/Exception.h Thu Nov 27 18:40:28 2025 +0100 +++ b/Utils/Exception.h Fri Nov 28 19:57:35 2025 +0100 @@ -51,6 +51,7 @@ # define EXPORT __declspec(dllimport) #endif +#if 0 class EXPORT Exception : public std::exception { @@ -65,6 +66,18 @@ /// Message contains, in UTF8 format. const char* what() const throw() override; }; +#endif + +class EXPORT Exception : public std::exception { +public: + explicit Exception(const QString& msg); + explicit Exception(const char* msg); + + const char* what() const noexcept override; + +private: + std::string _msg; +}; //////////////////////////////////////////////////////////////////////////////
--- a/main.cpp Thu Nov 27 18:40:28 2025 +0100 +++ b/main.cpp Fri Nov 28 19:57:35 2025 +0100 @@ -76,13 +76,14 @@ } \ } while(0) #endif +#if 0 #define LOG_TRACE(msg) \ do { \ if(Log::minLevel <= Log::LEVEL_TRACE) { \ LogAction(Log::LEVEL_TRACE, __FILE__, __LINE__, LOG_FUNCTION_) << QString("%1").arg(msg); \ } \ } while(0) - +#endif #ifdef Q_OS_WIN32 auto os = QOperatingSystemVersion::current();
