Qt程序运行出错。FTH: (3460): *** Fault tolerant heap shim applied to current process. T
程序源码如下:
mylistwidgetitem.h文件:
#ifndef MYLISTWIDGETITEM_H
#define MYLISTWIDGETITEM_H
#include <QWidget>
#include <QCheckBox>
#include <QRadioButton>
#include <QListWidget>
#include <QListWidgetItem>
#include <QToolButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
class MyListWidgetItem : public QWidget
{ Q_OBJECTpublic:
//explicit //MyListWidgetItem(QString regionAddressArg,QList<QString> meterAddressListArg,QWidget *parent = 0);
MyListWidgetItem(QString regionAddressArg,QList<QString> meterAddressListArg,QWidget *parent);private:
void initialMainWindow();
QString regionAddress;
QList<QString> meterAddressList;
signals:public slots:
};#endif // MYLISTWIDGETITEM_H
mylistwidgetitem.cpp文件
#include "mylistwidgetitem.h"MyListWidgetItem::MyListWidgetItem(QString regionAddressArg,QList<QString> meterAddressListArg,QWidget *parent) : QWidget(parent){
regionAddress = regionAddressArg;
meterAddressList = meterAddressListArg;
initialMainWindow();
}
void MyListWidgetItem::initialMainWindow(){
QCheckBox *regionCheckBox = new QCheckBox(regionAddress,this);
regionCheckBox->setFixedSize(100,20);
QRadioButton *allSelectRadio = new QRadioButton(tr("全选"),this);
allSelectRadio->setFixedSize(60,20);
QRadioButton *againSelectRadio = new QRadioButton(tr("反选"),this);
againSelectRadio->setFixedSize(60,20);
QToolButton *headToolButton = new QToolButton(this);
headToolButton->setText(tr("隐藏"));
headToolButton->setFixedSize(50,20);
QHBoxLayout *headLayout = new QHBoxLayout;
headLayout->setMargin(0);
headLayout->setSpacing(0);
headLayout->addWidget(regionCheckBox);
headLayout->addWidget(allSelectRadio);
headLayout->addWidget(againSelectRadio);
headLayout->addStretch();
headLayout->addWidget(headToolButton);
QListWidget *meterAddListWidget = new QListWidget;
meterAddListWidget->setViewMode(QListView::IconMode);
meterAddListWidget->setResizeMode(QListView::Adjust);
for(int i = 0; i < 30; i++){
QListWidgetItem *item = new QListWidgetItem("112233445566");
item->setCheckState(Qt::Unchecked);
meterAddListWidget->addItem(item);
}
//添加主布局
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(2);
mainLayout->addLayout(headLayout);
mainLayout->addWidget(meterAddListWidget);
this->setLayout(mainLayout);
}
mylistwidget.h文件:
#ifndef MYLISTWIDGET_H#define MYLISTWIDGET_H#include <QWidget>#include "mylistwidgetitem.h"class MyListWidget : public QWidget{
Q_OBJECTpublic:
//explicit
//MyListWidget(QWidget *parent = 0);
MyListWidget(QWidget *parent);
~MyListWidget();
private:
QString *regionAddress;
QList<QString> meterAddressList1;
QList<QString> meterAddressList2;signals:public slots:
};#endif // MYLISTWIDGET_H
mylistwidget.cpp文件:
#include "mylistwidget.h"#include "mylistwidgetitem.h"#include <QVBoxLayout>#include <QDebug>MyListWidget::MyListWidget(QWidget *parent) : QWidget(parent){
meterAddressList1 << "112233445566" << "112233445566";
meterAddressList2 << "112233445566" << "112233445566";
qDebug() << "hello";
MyListWidgetItem *mylistWidgetItem1 = new MyListWidgetItem("112233445566",meterAddressList1,this);
MyListWidgetItem *mylistWidgetItem2 = new MyListWidgetItem("112233445577",meterAddressList2,this);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->addWidget(mylistWidgetItem1);
mainLayout->addWidget(mylistWidgetItem2);
this->setLayout(mainLayout);
}
MyListWidget::~MyListWidget(){}
mainwindow.cpp文件
#include "mainwindow.h"#include "ui_mainwindow.h"#include "mylistwidget.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
ui->setupUi(this);
MyListWidget *myListWidget = new MyListWidget(this);
//myListWidget->sayHello();
this->setCentralWidget(myListWidget);
}
MainWindow::~MainWindow(){ delete ui;}
运行之后出现如下提示:
F:\qtProject\myListWidget\myListWidget-build-desktop\debug\myListWidget.exe 启动中...
FTH: (3460): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***
hello
F:\qtProject\myListWidget\myListWidget-build-desktop\debug\myListWidget.exe 退出, 代码: 0
请问是什么错误 。请各位指教 Qt 自定义控件
[解决办法]
重新rebuild all看一下,
[解决办法]
#ifndef MYLISTWIDGETITEM_H
#define MYLISTWIDGETITEM_H
#include <QWidget>
#include <QCheckBox>
#include <QRadioButton>
#include <QListWidget>
#include <QListWidgetItem>
#include <QToolButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <qdebug.h>
class MyListWidgetItem : public QWidget
{
Q_OBJECT
public:
MyListWidgetItem(QString regionAddressArg, QList<QString> meterAddressListArg, QWidget *parent) : QWidget(parent)
{
regionAddress = regionAddressArg;
meterAddressList = meterAddressListArg;
initialMainWindow();
}
private:
void initialMainWindow()
{
QCheckBox *regionCheckBox = new QCheckBox(regionAddress,this);
regionCheckBox->setFixedSize(100,20);
QRadioButton *allSelectRadio = new QRadioButton(tr("全选"),this);
allSelectRadio->setFixedSize(60,20);
QRadioButton *againSelectRadio = new QRadioButton(tr("反选"),this);
againSelectRadio->setFixedSize(60,20);
QToolButton *headToolButton = new QToolButton(this);
headToolButton->setText(tr("隐藏"));
headToolButton->setFixedSize(50,20);
QHBoxLayout *headLayout = new QHBoxLayout;
headLayout->setMargin(0);
headLayout->setSpacing(0);
headLayout->addWidget(regionCheckBox);
headLayout->addWidget(allSelectRadio);
headLayout->addWidget(againSelectRadio);
headLayout->addStretch();
headLayout->addWidget(headToolButton);
QListWidget *meterAddListWidget = new QListWidget;
meterAddListWidget->setViewMode(QListView::IconMode);
meterAddListWidget->setResizeMode(QListView::Adjust);
for(int i = 0; i < 30; i++){
QListWidgetItem *item = new QListWidgetItem("112233445566");
item->setCheckState(Qt::Unchecked);
meterAddListWidget->addItem(item);
}
//添加主布局
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(2);
mainLayout->addLayout(headLayout);
mainLayout->addWidget(meterAddListWidget);
this->setLayout(mainLayout);
}
QString regionAddress;
QList<QString> meterAddressList;
signals:
public slots:
};
class MyListWidget : public QWidget {
Q_OBJECT
public:
MyListWidget(QWidget *parent) : QWidget(parent)
{
meterAddressList1 << "112233445566" << "112233445566";
meterAddressList2 << "112233445566" << "112233445566";
qDebug() << "hello";
MyListWidgetItem *mylistWidgetItem1 = new MyListWidgetItem("112233445566",meterAddressList1,this);
MyListWidgetItem *mylistWidgetItem2 = new MyListWidgetItem("112233445577",meterAddressList2,this);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->addWidget(mylistWidgetItem1);
mainLayout->addWidget(mylistWidgetItem2);
this->setLayout(mainLayout);
}
~MyListWidget()
{
}
private:
QString *regionAddress;
QList<QString> meterAddressList1;
QList<QString> meterAddressList2;
signals:
public slots:
};
#endif
int main(int argc, char**argv)
{
QApplication app(argc,argv);
MyListWidget listWidget(NULL);
listWidget.show();
return app.exec();
}
这是我的测试代码,没有问题
[解决办法]
“清理项目”,“重新构建”
[解决办法]
不是有句话吗?学历是过去式,能力是现在式,学习力才是将来式,人生中大部分时间还是靠学习力的,所以不要有依赖性,相信自己能行的,自学才是硬道理。