我有一个 QML 应用程序(通过属性、Q_INVOKABLE 等)链接到 C++ 代码。我可以使用 qmlscene 在没有大部分 C++ 框架的情况下启动 QML 应用程序,并且没有明显的问题(除了丢失的数据和应该从 C++ 端提供的功能)。
但是,当我构建和部署代码时,我在 QQmlApplicationEngine::load() 调用期间在 Qt 框架内遇到段错误。
我创建了一个简化的“虚拟”应用程序,它似乎会触发完全相同的问题。
C++ 应用程序:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "SigCatcher.hpp" // Proprietary code
int main(
int argc,
char *argv[])
{
SigCatcher sig_catcher; // Just catches signals & prints stacktrace
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(
QUrl(QStringLiteral("qrc:/main.qml")));
return 0;
}
请注意,如果没有 SigCather,我仍然会遇到段错误,只是没有堆栈跟踪。因此,如果您注释掉 SigCatcher 导入和声明,则此示例是可重现的。
main.qml:
import QtQuick 2.5
import QtQuick.Controls 1.3
import QtCharts 2.0
ApplicationWindow {
id: winRoot
visible: true
width: 1024 - 24
height: 768 - 80
minimumWidth: width
minimumHeight: height
maximumHeight: minimumHeight
maximumWidth: minimumWidth
ChartView {
id: sparkline
anchors.top: parent.top
anchors.right: parent.right
anchors.left: parent.left
}
}
这里几乎什么都没有,这让我相信 ChartView 类型本身可能有错误。
可能会发生什么?我什至不知道如何调试它;据我所知,在调用 QGuiApplication::exec().engine::load() 期间使用 console.log
编辑: 阐明该应用程序可以与 qmlscene 一起正常工作(我第一次写这个问题时并不知道这一点)。
编辑 2:用显示相同问题的完整非专有示例(堆栈跟踪稍短)替换了之前的示例,该示例由从专有代码中精心挑选的片段组成。
平台信息:Qt 5.5.1 运行在 64 位 Debian 8 上;我的应用程序是使用 GCC 5.1 编译的,但我在 4.9.2 和 Clang 3.7.0 的预发布版本中看到了相同的错误,该版本现在大约有 6 个月了。我也尝试过使用 Qt 5.4.0(这需要导入 QtQuick 2.4 而不是 2.5)。
堆栈跟踪:
../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN22TracePrinterImpl_Linux16Print_stackTraceEv+0x42)[0x401e54]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN12TracePrinter16Print_stackTraceEv+0x9)[0x401e7d]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN20SigCatcherImpl_Linux15OnCatch_signal_Ei+0x68)[0x4022c6]
/lib/x86_64-linux-gnu/libc.so.6(+0x35180)[0x7fe0a2234180]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZN18QWidgetTextControl14setCursorWidthEi+0x55)[0x7fe0a527fb15]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZN18QWidgetTextControlC1EP7QObject+0x5d)[0x7fe0a527fced]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(+0x443047)[0x7fe0a53a6047]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZNK17QGraphicsTextItem8documentEv+0xd)[0x7fe0a53a633d]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x63821)[0x7fe098d74821]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x56cd3)[0x7fe098d67cd3]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5727d)[0x7fe098d6827d]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x597d6)[0x7fe098d6a7d6]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5bb7c)[0x7fe098d6cb7c]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5fb8f)[0x7fe098d70b8f]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/libqtchartsqml2.so(+0x2f044)[0x7fe099072044]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/libqtchartsqml2.so(+0x16680)[0x7fe099059680]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZNK8QQmlType6createEv+0x3b)[0x7fe0a436e07b]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cf472)[0x7fe0a43cf472]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cc85d)[0x7fe0a43cc85d]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cd45e)[0x7fe0a43cd45e]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cde8e)[0x7fe0a43cde8e]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cea8b)[0x7fe0a43cea8b]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cfcef)[0x7fe0a43cfcef]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN20QQmlComponentPrivate11beginCreateEP15QQmlContextData+0x145)[0x7fe0a43592e5]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN13QQmlComponent6createEP11QQmlContext+0x68)[0x7fe0a4359728]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN28QQmlApplicationEnginePrivate13_q_finishLoadEP7QObject+0x262)[0x7fe0a43c0de2]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN28QQmlApplicationEnginePrivate9startLoadERK4QUrlRK10QByteArrayb+0xd2)[0x7fe0a43c1082]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN21QQmlApplicationEngine4loadERK4QUrl+0x1d)[0x7fe0a43c10bd]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(main+0x84)[0x401ae4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fe0a2220b45]
../obj/X64_ATOM/debug/GUI/AucLocalGui2[0x401959]
最佳答案
给你。您需要引入 Qt Widgets 依赖项:
Note: Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View Framework for drawing, QApplication must be used. The project created with the wizard is usable with Qt Charts after the QGuiApplication is replaced with QApplication.
来自 http://doc.qt.io/QtCharts/qtcharts-qmlmodule.html
这与我的猜测一致,即问题出在应用程序主题中,当您使用纯 QML 应用程序 (QGuiApplication) 与更多原生 QtWidgets 应用程序 (QApplication) 时,这是非常不同的。
关于c++ - QtQuick ChartView QML 对象段错误在加载期间导致 QML 引擎段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34099236/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
我在Rails工作并有以下类(class):classPlayer当我运行时bundleexecrailsconsole然后尝试:a=Player.new("me",5.0,"UCLA")我回来了:=>#我不知道为什么Player对象不会在这里初始化。关于可能导致此问题的操作/解释的任何建议?谢谢,马里奥格 最佳答案 havenoideawhythePlayerobjectwouldn'tbeinitializedhere它没有初始化很简单,因为你还没有初始化它!您已经覆盖了ActiveRecord::Base初始化方法,但您没有调