-1
我正在使用Qt5。在我編寫的程序中,我有一個非常簡單的構造函數的類。問題是,當我檢查Valgrind的問題時,我在每個任務中都會收到「無效的大小寫」。在構造函數中寫入大小4的錯誤
這是標頭:
#ifndef RS22812_H
#define RS22812_H
#include <QObject>
class RS22812 : public QObject
{
Q_OBJECT
public:
explicit RS22812(QObject *parent = 0);
~RS22812();
private:
uint mode;
Flags flags;
QString byte2Digit(uchar byte);
signals:
void modeChanged(uint newmode);
public slots:
void newValue(const QByteArray &data);
};
#endif // RS22812_H
而在cpp文件構造定義:
RS22812::RS22812(QObject *parent) : QObject(parent)
{
mode=0;
}
Valgrind的給我誤差在兩者的QObject(父)和模式= 0:
Invalid write of size 4
in RS22812::RS22812(QObject*) in /home/javi/ProgrammingProjects/multimeterGUI/rs22812.cpp:4
1: RS22812::RS22812(QObject*) in /home/javi/ProgrammingProjects/multimeterGUI/rs22812.cpp:4
2: MainWindow::MainWindow(QWidget*) in /home/javi/ProgrammingProjects/multimeterGUI/mainwindow.cpp:29
3: main in /home/javi/ProgrammingProjects/multimeterGUI/main.cpp:7
Address 0x1c4ad500 is 0 bytes after a block of size 16 alloc'd 1: operator new(unsigned long) in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
2: MainWindow::MainWindow(QWidget*) in /home/javi/ProgrammingProjects/multimeterGUI/mainwindow.cpp:29
3: main in /home/javi/ProgrammingProjects/multimeterGUI/main.cpp:7
Invalid write of size 4
in RS22812::RS22812(QObject*) in /home/javi/ProgrammingProjects/multimeterGUI/rs22812.cpp:6
1: RS22812::RS22812(QObject*) in /home/javi/ProgrammingProjects/multimeterGUI/rs22812.cpp:6
2: MainWindow::MainWindow(QWidget*) in /home/javi/ProgrammingProjects/multimeterGUI/mainwindow.cpp:29
3: main in /home/javi/ProgrammingProjects/multimeterGUI/main.cpp:7
Address 0x1c4ad500 is 0 bytes after a block of size 16 alloc'd 1: operator new(unsigned long) in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so
2: MainWindow::MainWindow(QWidget*) in /home/javi/ProgrammingProjects/multimeterGUI/mainwindow.cpp:29
3: main in /home/javi/ProgrammingProjects/multimeterGUI/main.cpp:7
我不明白這麼簡單的賦值是如何導致錯誤的。感謝您的建議。
你如何使用你的課堂?你的'MainWindow'構造函數是做什麼的?你能否請嘗試創建一個[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)並向我們展示? (你現在應該知道的東西,曾經是這裏的會員很久) –