Код приведённый ниже вызывает некорректное завершение программы.
Если вызывать функции на прямую через if ошибки не возникает.
HEAP[MAN2_GUI.exe]: Heap block at 0000000000395A00 modified at 000000000039626C past requested size of 85c
HEAP[MAN2_GUI.exe]: Invalid address specified to RtlValidateHeap( 0000000000350000, 0000000000395A10 )
Program: ..._GUI-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\debug\MAN2_GUI.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 888
Expression: _CrtIsValidHeapPointer(block)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
Program: ..._GUI-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\debug\MAN2_GUI.exe
HEAP CORRUPTION DETECTED: after Normal block (#1903) at 0x0000000000395A40.
CRT detected that the application wrote to memory after end of heap buffer.
(Press Retry to debug the application)
HEAP[MAN2_GUI.exe]: Heap block at 0000000000395A00 modified at 000000000039626C past requested size of 85c
*.h
enum COMMAND {
PING,
...
...
BUFFER_OVERFLOW = 0xDF,
WRONG_COMMAND = 0xEF,
};
signals:
void U(int ch, float v);
void ManChannelDetected(int ch);
private:
void CmdPing();
void CmdNullFunction();
typedef void (MyProtocol::*pFunc)();
pFunc CmdArray[0xFF];
*.cpp
конструктор
for (int i = 0; i < 0xFF; ++i) {
CmdArray[i] = &MyProtocol::CmdNullFunction;
}
CmdArray[PING] = &MyProtocol::CmdPing;
connect(this, &QSerialPort::readyRead, this, &MyProtocol::readyRead);
Cлот, использование.
void MyProtocol::readyRead()
{
QMutexLocker locker(&readMutex);
...
(this->*CmdArray[Data[4]])();
...
}
"Каллбак"
void MyProtocol::CmdPing()
{
Channels.append((uint8_t)Data[5]);
emit ManChannelDetected((uint8_t)Data[5]);
}