0

自一周以来,我的 Qt 应用程序无法正常工作。我不熟悉这种堆损坏、访问冲突等东西。现在我知道它“很痛”,-)

同时我安装了应用程序验证器。我正在使用 VS2010、Qt 4.8.4、qwt 6.0.0。现在我将 GUI 类减少到最低限度,但仍然通过应用程序验证程序获得访问冲突。这是图形用户界面代码:

#include "mygui.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MYGUI w;
    w.show();
    return a.exec();
}

mygui.h:

#ifndef PFEGUI_H
#define PFEGUI_H

#include <QtGui/QMainWindow>
#include "ui_mygui.h"

#include <myengine.hpp>

class MYGUI : public QMainWindow
{
    Q_OBJECT

public:
    MYGUI(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~MYGUI();

    Ui::MYGUIClass ui;

private:
    boost::shared_ptr<MYengine> myEngine_; 
    boost::shared_ptr<QMenu> treeWidgetMenu_;
    boost::shared_ptr<QAction> treeWidgetMenuDeleteAction_;

};

mygui.cpp:

#include "mygui.h"

MYGUI::MYGUI(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);
    myEngine_ = boost::shared_ptr<MYengine>(new MYengine());
}

MYGUI::~MYGUI() {}

和大型自动生成的 ui_mygui.h (由于字符限制,我在中间跳过了一些部分):

/********************************************************************************
** Form generated from reading UI file 'mygui.ui'
**
** Created: Thu 11. Apr 22:55:21 2013
**      by: Qt User Interface Compiler version 4.8.4
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/

#ifndef UI_MYGUI_H
#define UI_MYGUI_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QDateEdit>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QFormLayout>
#include <QtGui/QFrame>
#include <QtGui/QGridLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLCDNumber>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QProgressBar>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QScrollArea>
#include <QtGui/QSlider>
#include <QtGui/QSpacerItem>
#include <QtGui/QSpinBox>
#include <QtGui/QStackedWidget>
#include <QtGui/QStatusBar>
#include <QtGui/QTabWidget>
#include <QtGui/QTextBrowser>
#include <QtGui/QToolBar>
#include <QtGui/QTreeWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include "qwt_plot.h"

QT_BEGIN_NAMESPACE

class Ui_MYGUIClass
{
public:
    QWidget *centralWidget;
    QTabWidget *tabWidgetMYGUI;
    QWidget *tab;
    QWidget *layoutWidget;
    QVBoxLayout *verticalLayout;
    QPushButton *pushButtonSzenarienBerechnen;
    QPushButton *pushButtonMYBerechnen;
    QWidget *layoutWidget1;
    QVBoxLayout *verticalLayout_2;
    QHBoxLayout *horizontalLayout_4;
    QProgressBar *progressBarMY;
    QLCDNumber *lcdNumberWatch;
    QScrollArea *scrollAreaOutput;
    QWidget *scrollAreaWidgetContents;
    QGridLayout *gridLayout_6;
    QTextBrowser *textBrowserOutput;
    QWidget *tab_2;
    QGroupBox *groupBox_2;
    QGridLayout *gridLayout_5;
    QGridLayout *gridLayout_4;
    QPushButton *pushButtonPortfolioPfeBerechnen;
    QTreeWidget *treeWidgetPortfolioSimPort;
    QGroupBox *groupBox_3;
    QGridLayout *gridLayout_2;
    QHBoxLayout *horizontalLayout_10;
    QLabel *label_4;
    QComboBox *comboBoxPortfolioCtpNumbers;
    QHBoxLayout *horizontalLayout_11;
    QPushButton *pushButtonPortfolioShowCtp;
    QPushButton *pushButtonPortfolioAddCtp;
    QPushButton *pushButtonPortfolioAddAll;
    QGroupBox *groupBox_5;
    QGridLayout *gridLayout_10;
    QStackedWidget *stackedWidgetPortfolioAddDeal;
    QWidget *pageVanillaSwap;
    QGridLayout *gridLayout_11;
    QHBoxLayout *horizontalLayout_5;
    QRadioButton *radioButtonPortfolioPayer;
    QRadioButton *radioButtonPortfolioReceiver;
    QHBoxLayout *horizontalLayout_9;
    QLabel *label_19;
    QSpacerItem *horizontalSpacer_2;
    QDoubleSpinBox *doubleSpinBoxPortfolioFixRate;
    QHBoxLayout *horizontalLayout_6;
    QLabel *label_8;
    QSpacerItem *horizontalSpacer;
    QComboBox *comboBoxPortfolioIndices;
    QFormLayout *formLayout;
    QLabel *label_15;
    QComboBox *comboBoxPortfolioFixFreq;
    QLabel *label_16;
    QComboBox *comboBoxPortfolioFloatFreq;
    QFormLayout *formLayout_2;
    QLabel *label_18;
    QComboBox *comboBoxPortfolioFixDC;
    QLabel *label_20;
    QComboBox *comboBoxPortfolioFloatDC;
    QSpacerItem *verticalSpacer;
    QWidget *pagefxproducts;
    QGridLayout *gridLayout_12;
    QSpacerItem *verticalSpacer_2;
    QHBoxLayout *horizontalLayout_16;
    QLabel *label_21;
    QDoubleSpinBox *doubleSpinBoxPortfolioFxSpot;
    QHBoxLayout *horizontalLayout_14;
    QLabel *label_13;
    QDoubleSpinBox *doubleSpinBoxPortfolioForwardRate;
    QHBoxLayout *horizontalLayout_13;
    QLabel *label_12;
    QComboBox *comboBoxPortfolioCurrencyPairs;
    QHBoxLayout *horizontalLayout_8;
    QLabel *label_11;
    QSpinBox *spinBoxPortfolioNominal2;
    QLabel *labelPortfolioCurrency2;
    QComboBox *comboBoxPortfolioBuySell;
    QHBoxLayout *horizontalLayout_7;
    QLabel *label_10;
    QSpacerItem *horizontalSpacer_3;
    QLineEdit *lineEditPortfolioDealMaturity;
    QSpacerItem *horizontalSpacer_6;
    QDateEdit *dateEditPortfolioEndDate;
    QHBoxLayout *horizontalLayout_12;
    QLabel *label_9;
    QSpacerItem *horizontalSpacer_5;
    QDateEdit *dateEditPortfolioStartDate;
    QHBoxLayout *horizontalLayout_2;
    QLabel *label_6;
    QComboBox *comboBoxPortfolioInstrumentNames;
    QHBoxLayout *horizontalLayout_3;
    QLabel *label_7;
    QSpinBox *spinBoxPortfolioNominal;
    QComboBox *comboBoxPortfolioCurrencies;
    QPushButton *pushButtonPortfolioAddDeal;
    QHBoxLayout *horizontalLayout;
    QLabel *label_14;
    QSpacerItem *horizontalSpacer_4;
    QComboBox *comboBoxPortfolioAddDealCtpNumbers;
    QFrame *line;
    QHBoxLayout *horizontalLayout_15;
    QLabel *label_17;
    QLineEdit *lineEditPortfolioNPV;
    QPushButton *pushButtonPortfolioCalculateNPV;
    QComboBox *comboBoxPortfolioCtpNumbers_2;
    QWidget *tab_3;
    QwtPlot *qwtPlot;
    QWidget *layoutWidget_2;
    QHBoxLayout *horizontalLayout_18;
    QLabel *label_23;
    QComboBox *comboBoxAnalysisContractNumbers;
    QWidget *layoutWidget_3;
    QHBoxLayout *horizontalLayout_19;
    QLabel *label_24;
    QComboBox *comboBoxAnalysisCompNumbers;
    QPushButton *pushButtonAnalysisPlotCtp;
    QPushButton *pushButtonAnalysisPlotContract;
    QPushButton *pushButtonAnalysisPlotComp;
    QWidget *layoutWidget2;
    QHBoxLayout *horizontalLayout_17;
    QLabel *label_22;
    QComboBox *comboBoxAnalysisCtpNumbers;
    QCheckBox *checkBoxAnalysisSimulationPaths;
    QCheckBox *checkBoxAnalysisStatisticCurves;
    QGroupBox *groupBox_11;
    QWidget *layoutWidget3;
    QHBoxLayout *horizontalLayout_39;
    QRadioButton *radioButtonAnalysisBarStyle;
    QRadioButton *radioButtonAnalysisTubeStyle;
    QGroupBox *groupBox_12;
    QWidget *layoutWidget4;
    QHBoxLayout *horizontalLayout_20;
    QLabel *label_25;
    QSpinBox *spinBoxAnalysisSimStep;
    QLabel *label_26;
    QDateEdit *dateEditAnalysisChoosenDate;
    QPushButton *pushButtonAnalysisShowMarketData;
    QWidget *tab_7;
    QwtPlot *qwtPlot_2;
    QGroupBox *groupBox_6;
    QSpinBox *spinBoxAnalysisSimStep_2;
    QPushButton *pushButton;
    QPushButton *pushButton_2;
    QPushButton *pushButton_3;
    QPushButton *pushButton_4;
    QWidget *OptionsTab;
    QGroupBox *groupBox;
    QWidget *layoutWidget5;
    QGridLayout *gridLayout;
    QLabel *label;
    QSpinBox *spinBoxSimSteps;
    QSlider *horizontalSliderSimSteps;
    QLabel *label_2;
    QSpinBox *spinBoxForwardSteps;
    QSlider *horizontalSliderSimSteps_2;
    QLabel *label_3;
    QDoubleSpinBox *spinBoxJumpProb;
    QGroupBox *groupBox_4;
    QLabel *label_5;
    QLineEdit *lineEditSettingsInstrumentFile;
    QPushButton *pushButtonSettingsInstFileBrowse;
    QTextBrowser *textBrowserPortfolioCtpTrades;
    QStackedWidget *stackedWidget_2;
    QWidget *page_3;
    QWidget *page_4;
    QMenuBar *menuBar;
    QMenu *menuOptions;
    QToolBar *mainToolBar;
    QStatusBar *statusBar;
    QButtonGroup *buttonGroup_2;

    void setupUi(QMainWindow *MYGUIClass)
    {
        if (MYGUIClass->objectName().isEmpty())
            MYGUIClass->setObjectName(QString::fromUtf8("MYGUIClass"));
        MYGUIClass->resize(1538, 777);
        centralWidget = new QWidget(MYGUIClass);
        centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
        tabWidgetMYGUI = new QTabWidget(centralWidget);
        tabWidgetMYGUI->setObjectName(QString::fromUtf8("tabWidgetMYGUI"));
        tabWidgetMYGUI->setGeometry(QRect(11, 0, 1521, 751));
        tabWidgetMYGUI->setIconSize(QSize(16, 16));
        tab = new QWidget();
        tab->setObjectName(QString::fromUtf8("tab"));
        layoutWidget = new QWidget(tab);
        layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
        layoutWidget->setGeometry(QRect(10, 50, 401, 62));
        verticalLayout = new QVBoxLayout(layoutWidget);
        verticalLayout->setSpacing(6);
        verticalLayout->setContentsMargins(11, 11, 11, 11);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        verticalLayout->setContentsMargins(0, 0, 0, 0);
        pushButtonSzenarienBerechnen = new QPushButton(layoutWidget);
        pushButtonSzenarienBerechnen->setObjectName(QString::fromUtf8("pushButtonSzenarienBerechnen"));
        pushButtonSzenarienBerechnen->setEnabled(true);
        QFont font;
        font.setPointSize(12);
        font.setBold(true);
        font.setWeight(75);
        pushButtonSzenarienBerechnen->setFont(font);
        pushButtonSzenarienBerechnen->setCheckable(false);

        verticalLayout->addWidget(pushButtonSzenarienBerechnen);

        pushButtonMYBerechnen = new QPushButton(layoutWidget);
        pushButtonMYBerechnen->setObjectName(QString::fromUtf8("pushButtonMYBerechnen"));
        pushButtonMYBerechnen->setEnabled(true);
        pushButtonMYBerechnen->setFont(font);
        pushButtonMYBerechnen->setCheckable(false);

        verticalLayout->addWidget(pushButtonMYBerechnen);


        verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);

        gridLayout_11->addItem(verticalSpacer, 4, 0, 1, 1);

        stackedWidgetPortfolioAddDeal->addWidget(pageVanillaSwap);
        pagefxproducts = new QWidget();
        pagefxproducts->setObjectName(QString::fromUtf8("pagefxproducts"));
        gridLayout_12 = new QGridLayout(pagefxproducts);
        gridLayout_12->setSpacing(6);
        gridLayout_12->setContentsMargins(11, 11, 11, 11);
        gridLayout_12->setObjectName(QString::fromUtf8("gridLayout_12"));
        verticalSpacer_2 = new QSpacerItem(20, 80, QSizePolicy::Minimum, QSizePolicy::Expanding);



// Tons of other autogenerated stuff are deleted here

        QTreeWidgetItem *___qtreewidgetitem = treeWidgetPortfolioSimPort->headerItem();
        ___qtreewidgetitem->setText(9, QApplication::translate("MYGUIClass", "MY Exposure", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(8, QApplication::translate("MYGUIClass", "MY Date", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(7, QApplication::translate("MYGUIClass", "MY", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(6, QApplication::translate("MYGUIClass", "Maturity", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(5, QApplication::translate("MYGUIClass", "int. NPV", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(4, QApplication::translate("MYGUIClass", "ext. NPV", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(3, QApplication::translate("MYGUIClass", "Comp Id", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(2, QApplication::translate("MYGUIClass", "Contract Id", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(1, QApplication::translate("MYGUIClass", "Ctp Id", 0, QApplication::UnicodeUTF8));
        ___qtreewidgetitem->setText(0, QApplication::translate("MYGUIClass", "Kategorie", 0, QApplication::UnicodeUTF8));
        groupBox_3->setTitle(QApplication::translate("MYGUIClass", "Add Counterparty", 0, QApplication::UnicodeUTF8));
        label_4->setText(QApplication::translate("MYGUIClass", "Counterparty number", 0, QApplication::UnicodeUTF8));
#ifndef QT_NO_TOOLTIP
        pushButtonPortfolioShowCtp->setToolTip(QApplication::translate("MYGUIClass", "<html><head/><body><p>Kundenportfolio anzeigen...</p></body></html>", 0, QApplication::UnicodeUTF8));
#endif // QT_NO_TOOLTIP
        pushButtonPortfolioShowCtp->setText(QApplication::translate("MYGUIClass", "Show", 0, QApplication::UnicodeUTF8));
        pushButtonPortfolioAddCtp->setText(QApplication::translate("MYGUIClass", "Add", 0, QApplication::UnicodeUTF8));
        pushButtonPortfolioAddAll->setText(QApplication::translate("MYGUIClass", "Add all", 0, QApplication::UnicodeUTF8));
        groupBox_5->setTitle(QApplication::translate("MYGUIClass", "Add Deal", 0, QApplication::UnicodeUTF8));
        radioButtonPortfolioPayer->setText(QApplication::translate("MYGUIClass", "Payer", 0, QApplication::UnicodeUTF8));
        radioButtonPortfolioReceiver->setText(QApplication::translate("MYGUIClass", "Receiver", 0, QApplication::UnicodeUTF8));
        label_19->setText(QApplication::translate("MYGUIClass", "Fix Rate (in %)", 0, QApplication::UnicodeUTF8));
        label_8->setText(QApplication::translate("MYGUIClass", "Index", 0, QApplication::UnicodeUTF8));
        label_15->setText(QApplication::translate("MYGUIClass", "Fix Freq", 0, QApplication::UnicodeUTF8));
        label_16->setText(QApplication::translate("MYGUIClass", "Float Freq", 0, QApplication::UnicodeUTF8));
        label_18->setText(QApplication::translate("MYGUIClass", "Fix DC", 0, QApplication::UnicodeUTF8));
        label_20->setText(QApplication::translate("MYGUIClass", "Float DC", 0, QApplication::UnicodeUTF8));
        label_21->setText(QApplication::translate("MYGUIClass", "Spot", 0, QApplication::UnicodeUTF8));
        label_13->setText(QApplication::translate("MYGUIClass", "Forward rate", 0, QApplication::UnicodeUTF8));
        label_12->setText(QApplication::translate("MYGUIClass", "Currency pair", 0, QApplication::UnicodeUTF8));
        label_11->setText(QApplication::translate("MYGUIClass", "Notional 2", 0, QApplication::UnicodeUTF8));
        spinBoxPortfolioNominal2->setSuffix(QString());
        labelPortfolioCurrency2->setText(QApplication::translate("MYGUIClass", "USD", 0, QApplication::UnicodeUTF8));
        label_10->setText(QApplication::translate("MYGUIClass", "Maturity", 0, QApplication::UnicodeUTF8));
        lineEditPortfolioDealMaturity->setInputMask(QApplication::translate("MYGUIClass", "00y + 00m;_", 0, QApplication::UnicodeUTF8));
        lineEditPortfolioDealMaturity->setText(QApplication::translate("MYGUIClass", "05y + 00m", 0, QApplication::UnicodeUTF8));
        label_9->setText(QApplication::translate("MYGUIClass", "Start date", 0, QApplication::UnicodeUTF8));
        label_6->setText(QApplication::translate("MYGUIClass", "Inst-Type", 0, QApplication::UnicodeUTF8));
        label_7->setText(QApplication::translate("MYGUIClass", "Notional", 0, QApplication::UnicodeUTF8));
        spinBoxPortfolioNominal->setSuffix(QString());
        pushButtonPortfolioAddDeal->setText(QApplication::translate("MYGUIClass", "Add", 0, QApplication::UnicodeUTF8));
        label_14->setText(QApplication::translate("MYGUIClass", "Kunde", 0, QApplication::UnicodeUTF8));
        label_17->setText(QApplication::translate("MYGUIClass", "NPV", 0, QApplication::UnicodeUTF8));
        lineEditPortfolioNPV->setText(QApplication::translate("MYGUIClass", "not calculated", 0, QApplication::UnicodeUTF8));
        pushButtonPortfolioCalculateNPV->setText(QApplication::translate("MYGUIClass", "Calculate", 0, QApplication::UnicodeUTF8));
        tabWidgetMYGUI->setTabText(tabWidgetMYGUI->indexOf(tab_2), QApplication::translate("MYGUIClass", "Portfolio", 0, QApplication::UnicodeUTF8));
        label_23->setText(QApplication::translate("MYGUIClass", "Contract number", 0, QApplication::UnicodeUTF8));
        label_24->setText(QApplication::translate("MYGUIClass", "Component number", 0, QApplication::UnicodeUTF8));
        pushButtonAnalysisPlotCtp->setText(QApplication::translate("MYGUIClass", "Plot", 0, QApplication::UnicodeUTF8));
        pushButtonAnalysisPlotContract->setText(QApplication::translate("MYGUIClass", "Plot", 0, QApplication::UnicodeUTF8));
        pushButtonAnalysisPlotComp->setText(QApplication::translate("MYGUIClass", "Plot", 0, QApplication::UnicodeUTF8));
        label_22->setText(QApplication::translate("MYGUIClass", "Counterparty number", 0, QApplication::UnicodeUTF8));
        checkBoxAnalysisSimulationPaths->setText(QApplication::translate("MYGUIClass", "Show simulated NPV Paths", 0, QApplication::UnicodeUTF8));
        checkBoxAnalysisStatisticCurves->setText(QApplication::translate("MYGUIClass", "Show statistics", 0, QApplication::UnicodeUTF8));
        groupBox_11->setTitle(QApplication::translate("MYGUIClass", "Style Statistics", 0, QApplication::UnicodeUTF8));
        radioButtonAnalysisBarStyle->setText(QApplication::translate("MYGUIClass", "Bars", 0, QApplication::UnicodeUTF8));
        radioButtonAnalysisTubeStyle->setText(QApplication::translate("MYGUIClass", "Tube", 0, QApplication::UnicodeUTF8));
        groupBox_12->setTitle(QApplication::translate("MYGUIClass", "Simulation Parameters", 0, QApplication::UnicodeUTF8));
        label_25->setText(QApplication::translate("MYGUIClass", "Sim Step", 0, QApplication::UnicodeUTF8));
        label_26->setText(QApplication::translate("MYGUIClass", "Date", 0, QApplication::UnicodeUTF8));
        pushButtonAnalysisShowMarketData->setText(QApplication::translate("MYGUIClass", "Show Market Data", 0, QApplication::UnicodeUTF8));
        tabWidgetMYGUI->setTabText(tabWidgetMYGUI->indexOf(tab_3), QApplication::translate("MYGUIClass", "Analysis MY", 0, QApplication::UnicodeUTF8));
        groupBox_6->setTitle(QApplication::translate("MYGUIClass", "GroupBox", 0, QApplication::UnicodeUTF8));
        pushButton->setText(QApplication::translate("MYGUIClass", "PushButton", 0, QApplication::UnicodeUTF8));
        pushButton_2->setText(QApplication::translate("MYGUIClass", "PushButton", 0, QApplication::UnicodeUTF8));
        pushButton_3->setText(QApplication::translate("MYGUIClass", "PushButton", 0, QApplication::UnicodeUTF8));
        pushButton_4->setText(QApplication::translate("MYGUIClass", "PushButton", 0, QApplication::UnicodeUTF8));
        tabWidgetMYGUI->setTabText(tabWidgetMYGUI->indexOf(tab_7), QApplication::translate("MYGUIClass", "Analysis MD", 0, QApplication::UnicodeUTF8));
        groupBox->setTitle(QApplication::translate("MYGUIClass", "Simulation parameters", 0, QApplication::UnicodeUTF8));
        label->setText(QApplication::translate("MYGUIClass", "Number of Simulation Steps", 0, QApplication::UnicodeUTF8));
        label_2->setText(QApplication::translate("MYGUIClass", "Number of Forward Steps", 0, QApplication::UnicodeUTF8));
        label_3->setText(QApplication::translate("MYGUIClass", "Jump Probability", 0, QApplication::UnicodeUTF8));
        groupBox_4->setTitle(QApplication::translate("MYGUIClass", "Input Files", 0, QApplication::UnicodeUTF8));
        label_5->setText(QApplication::translate("MYGUIClass", "Instrument File:", 0, QApplication::UnicodeUTF8));
        pushButtonSettingsInstFileBrowse->setText(QApplication::translate("MYGUIClass", "...", 0, QApplication::UnicodeUTF8));
        tabWidgetMYGUI->setTabText(tabWidgetMYGUI->indexOf(OptionsTab), QApplication::translate("MYGUIClass", "Settings", 0, QApplication::UnicodeUTF8));
        menuOptions->setTitle(QApplication::translate("MYGUIClass", "Options", 0, QApplication::UnicodeUTF8));
    } // retranslateUi

};

namespace Ui {
    class MYGUIClass: public Ui_MYGUIClass {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_MYGUI_H

这编译没有任何问题。但是当我启动应用程序(使用应用程序验证程序)时,我在方法之后得到一个触发断点

void setupUi(QMainWindow *MYGUIClass)

在ui_mygui.h中完成,进入MYengine的构造函数。没有执行构造函数的任何行,它只是触发一个断点。这是验证者报告:

======================================== VERIFIER STOP 00000013:pid 0x1CDC:第一次机会访问违规对于当前堆栈跟踪。

0AF79000 : Invalid address causing the exception.
00E15057 : Code address executing the invalid access.
0032F134 : Exception record.
0032F184 : Context record.

======================================== 这个验证器停止是可继续的。调试后使用“go”继续。

========================================

如果我只是删除单行

myEngine_ = boost::shared_ptr<MYengine>(new MYengine());

在 mygui.cpp 中,Gui 打开,没有应用程序验证程序断点,一切似乎都运行良好。

我完全迷路了。class MYengine 是一个嵌入在静态库中的大型类,还有数百个附加类。错误发生在 Myengine 的构造函数的第一行执行之前。那么为什么有或没有上述行的行为如此不同?任何想法将不胜感激。这段代码开始让我成功,-(

4

1 回答 1

0

在不知道其余代码的情况下,我很确定您不应该将 Qt 指针放入 boost 共享指针中 - Qt 有自己的对象生命周期管理,并且会在不询问共享指针的情况下删除内存,因此您最终可能会得到 boost - 指向已释放内存的指针。但这仅适用于

boost::shared_ptr<QMenu> treeWidgetMenu_;
boost::shared_ptr<QAction> treeWidgetMenuDeleteAction_;

应该分别是 QMenu* 和 QAction*。

我假设 MYengine 不是 Qt 类。或许,您应该向我们展示 MyEngine 的接口,以便我们了解,为什么指向 MyEngine 的共享指针会造成麻烦。

于 2013-04-12T13:10:28.850 回答