错误提示:
最近遇到一个有点意思的现象,一份代码运行正常,但是只要在代码中添加了一个QTimer变量,则程序退出时异常结束,错误提示如下:
double free or corruption (!prev)
16:15:03: 程序异常结束。
16:15:03: The process was ended forcefully.
当然,个人猜测肯定不单单是因为这个变量加入的原因,看错误提示是内存多次释放导致的,但是找了一下也没找到地方,应该是整个代码写得不太好,这个变量的定义触发了其他错误。
头文件如下:
#ifndef LANMANAGERSO_H
#define LANMANAGERSO_H
#include <QWidget>
#include "LanManagerSo_global.h"
#include <QKeyEvent>
#include <QMenu>
#include "Configure.h"
#include "tablemodel.h"
#include "tasksinterface.h"
#include "scanclients.h"
namespace Ui {
class LanManagerSo;
}
class LANMANAGERSO_EXPORT LanManagerSo : public QWidget
{
Q_OBJECT
public:
explicit LanManagerSo(QWidget *parent = nullptr);
~LanManagerSo();
//接口
public:
void btn_rescan_clicked(){on_btn_rescan_clicked();}
void btn_apply_clicked(){on_btn_apply_clicked();}
void btn_start_clicked(){on_btn_start_clicked();}
public slots:
//Master
void uploadProgress(qint64, qint64);
void uploadFinished();
private slots:
void enableRescanButton(bool bFinished);
void checkScanResult();
void showScanResult(const QList<ClientInfo>& lClients);
void showToolTip(const QModelIndex &index);
void CheckTestDataProgress();
void updateProgressValue();
void updateProgressValue(qint64 cur, qint64 total, const QString& strHost);
void ouputInfomation(const QString& strInfo);
void ouputInfomation(bool, const QString& strInfo);
private slots:
void on_menuBtn_clicked();
void on_minBtn_clicked();
void on_nomalBtn_clicked();
void on_closeBtn_clicked();
void on_btn_rescan_clicked();
void on_btn_apply_clicked();
void on_btn_start_clicked();
private:
bool checkIfLeftClients();
bool setIfLeftClients();
void updateTableViewClients();
private:
Ui::LanManagerSo *ui;
bool m_bMousePressed;
_config_s m_cfg;
ScanClients* m_pSS;
QList<ClientInfo> m_lClients;
std::vector<ClientInfo> vSelectClients;
QTimer m_checkTestDataTimer;
QTimer m_clientResponseTimer;
QTimer m_testTimeoutTimer;
QTimer m_progressTimer;
TableModel* m_pTableModel;
TasksInterface* m_pTi;
QPoint m_pointStart;
QPoint m_pointPress;
QAction *m_AactionAboutQt;
QMenu *m_menu;
void changeEvent(QEvent* event);
void keyPressEvent(QKeyEvent* event);
void resizeEvent ( QResizeEvent * event );
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
//成员变量初始化;
void initData();
void loadBackground();
void setTableViewColumWidth();
QString atuoShowMB(const int& nMB);
};
#endif // LANMANAGERSO_H
而如果注释掉这个变量:
则程序正常退出:
exited with code 0
需要说明一下的是,这个函数本身导出了库,而且函数本身有点复杂,所以这个问题并不能单单认为是这个变量引起的错误。
另外,这个错误换了几台机器依然可以复现,目前暂未找到解决办法,暂时选择了禁用这个变量,因为经过尝试改变量名称错误依然存在。