fix: change QString to QByteArray for exception message handling

This commit is contained in:
Nick Bolton 2026-05-26 16:34:16 +01:00 committed by Chris Rizzitello
parent 6212f9bec6
commit bf65080b8b
3 changed files with 12 additions and 9 deletions

View file

@ -31,8 +31,8 @@ const char *BaseException::what() const throw()
return what; return what;
} }
m_what = getWhat(); m_what = getWhat().toLocal8Bit();
return qPrintable(m_what); return m_what.constData();
} }
QString BaseException::format(const char * /*id*/, const char *fmt, ...) const noexcept QString BaseException::format(const char * /*id*/, const char *fmt, ...) const noexcept

View file

@ -11,6 +11,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <QByteArray>
#include <QString> #include <QString>
//! Exception base class //! Exception base class
@ -45,5 +46,5 @@ protected:
virtual QString format(const char *id, const char *defaultFormat, ...) const noexcept; virtual QString format(const char *id, const char *defaultFormat, ...) const noexcept;
private: private:
mutable QString m_what; mutable QByteArray m_what;
}; };

View file

@ -11,6 +11,8 @@
#include "base/BaseException.h" #include "base/BaseException.h"
#include "io/IOException.h" #include "io/IOException.h"
#include <QByteArray>
/** /**
* @brief SocketException generic socket exception * @brief SocketException generic socket exception
*/ */
@ -81,11 +83,11 @@ public:
{ {
if (m_state == kFirst) { if (m_state == kFirst) {
m_state = kFormat; m_state = kFormat;
m_formatted = getWhat(); m_formatted = getWhat().toLocal8Bit();
m_state = kDone; m_state = kDone;
} }
if (m_state == kDone) { if (m_state == kDone) {
return qPrintable(m_formatted); return m_formatted.constData();
} else { } else {
return IOCloseException::what(); return IOCloseException::what();
} }
@ -102,7 +104,7 @@ private:
kDone kDone
}; };
mutable EState m_state; mutable EState m_state;
mutable QString m_formatted; mutable QByteArray m_formatted;
}; };
/** /**
@ -125,11 +127,11 @@ public:
{ {
if (m_state == kFirst) { if (m_state == kFirst) {
m_state = kFormat; m_state = kFormat;
m_formatted = getWhat(); m_formatted = getWhat().toLocal8Bit();
m_state = kDone; m_state = kDone;
} }
if (m_state == kDone) { if (m_state == kDone) {
return qPrintable(m_formatted); return m_formatted.constData();
} else { } else {
return SocketException::what(); return SocketException::what();
} }
@ -143,7 +145,7 @@ private:
kDone kDone
}; };
mutable EState m_state; mutable EState m_state;
mutable QString m_formatted; mutable QByteArray m_formatted;
}; };
/** /**