You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio下Qt项目运行时对象误判问题求助

问题描述与求助

环境信息

  • 操作系统:Windows 11
  • 开发环境:Visual Studio Community 2022 17.12.3
  • Qt版本:6.8.1(msvc2022_64)
  • 项目结构:两个基于Qt的C项目(自动化交易方案、单元/回归测试程序)共享自定义C库,此前运行完全正常

问题背景

安装包含g++的默认Cygwin后,清理重建项目出现异常;卸载Cygwin、升级Qt至6.8.1、升级VS至17.12.3后问题仍未解决,已手动删除debug/x64目录并检查系统PATH无异常项。


问题1:单元/回归测试程序触发read access violation

相关代码:

void TradeToolsTest::initTestCase(void)
{
    QSharedPointer<UnderlyingAsset> spy = TradeToolsTest::parentLists->getUnderlyingAsset("SPY");

    QSharedPointer<QMap<qint64, QSharedPointer<Bar>>> bar30 = QSharedPointer<QMap<qint64, QSharedPointer<Bar>>>(new QMap<qint64, QSharedPointer<Bar>>);

    // Convert the bars from JSON to a list of Bars
    QSharedPointer<QVector<QSharedPointer<Bar>>> tempBar = api->jsonArrayToItemArray<Bar>(this->mockData["bars"]["spy"]["minute"]["30"].array(), (processJSONObject)TradeTools::Financial::jsonToBar, TradeToolsTest::parentLists);

    // Insert the bars into the expected container type
    for(QVector<QSharedPointer<Bar>>::iterator itBar=tempBar->begin(), endBar=tempBar->end(); itBar!=endBar; itBar++)
        bar30->insert((*itBar)->timestamp, *itBar);

    // Add the bars to the asset
    spy->addBars(timeframe30, bar30, TradeToolsTest::state, adequateBarCount, TradeToolsTest::parentLists, TradeToolsTest::internalComm, TradeToolsTest::barAdded);
}

bool OQIAsset::addBars(const BarTime barTime, const QSharedPointer<QMap<qint64, QSharedPointer<Bar>>> bar, const QSharedPointer<AppState> appState, bool &adequateBarCount, const QSharedPointer<ParentLists> parentLists, const QSharedPointer<InternalCommunication> internalComm, const BarAdded realBarAdded)
{
    return TradeTools::Financial::addBars<OQIAsset>(this, barTime, bar, this->strikeIncrement, appState, adequateBarCount, parentLists, internalComm, realBarAdded);
}

注:UnderlyingAsset类继承自OQIAsset类

调试现象:

  • 在OQIAsset::addBars的返回语句处断点,监视窗口中bar.value的QMap::size显示为异常大值(预期为200)
  • 回到调用方TradeToolsTest::initTestCase监视bar30.value,QMap::size为预期的200,且两者的共享对象指针地址完全一致;移除bar参数的const修饰后问题无改善

问题2:自动化交易项目报错QWidget: Must construct a QApplication before a QWidget

相关代码:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Systematic w;

    w.show();

    return a.exec();
}

Systematic::Systematic(QWidget *parent)
    : QMainWindow(parent)
{
    Systematic::initUI();
}

void Systematic::initUI(void)
{
    Systematic::profitLossChart = new LineChartView;
}

内容的提问来源于stack exchange,提问作者MikeO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 17:43:13