Program crashing on exec()
-
Hello,
I am having a program crash when it reaches the QApplication's exec method. Here is the stacktrace from it.
@
Program received signal SIGABRT, Aborted.
0x00007fff872ac212 in __pthread_kill ()
(gdb) bt
#0 0x00007fff872ac212 in __pthread_kill ()
#1 0x00007fff8c1b4b54 in pthread_kill ()
#2 0x00007fff8c1f8dce in abort ()
#3 0x00007fff8c5d99eb in abort_message ()
#4 0x00007fff8c5d739a in default_terminate ()
#5 0x00007fff8a27d887 in _objc_terminate ()
#6 0x00007fff8c5d73c9 in safe_handler_caller ()
#7 0x00007fff8c5d7424 in std::terminate ()
#8 0x00007fff8c5d861b in __cxa_rethrow ()
#9 0x00007fff8a27d575 in objc_exception_rethrow ()
#10 0x00007fff86450146 in CFRunLoopRunSpecific ()
#11 0x00007fff8228beb4 in RunCurrentEventLoopInMode ()
#12 0x00007fff8228bc52 in ReceiveNextEventCommon ()
#13 0x00007fff8228bae3 in BlockUntilNextEventMatchingListInMode ()
#14 0x00007fff8a4da533 in _DPSNextEvent ()
#15 0x00007fff8a4d9df2 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#16 0x00007fff8a4d11a3 in -[NSApplication run] ()
#17 0x0000000102f1652b in QCocoaEventDispatcher::processEvents ()
#18 0x0000000100c88a33 in QEventLoop::exec ()
#19 0x0000000100c8bb25 in QCoreApplication::exec ()
#20 0x0000000100005f1f in main ()
@I believe the problem lies with me using QNetworkAccessManager.
I am creating many copies of "this":https://github.com/qutereddit/qutereddit/blob/addsubreddit/src/article.cpp class.
Any help is appreciated.
-
Hi,
Does it also crash using only one copy of the class ?
Could you share your code (a minimal version that also crash) ?
-
Well, it turns out to be an error with me throwing exceptions.
@
void Article::parseMetaArticle(QJsonObject dataObject)
{
//qDebug() << dataObject;
qDebug() << "Before is does anything";
qDebug() << dataObject.size();if(dataObject.value("domain").isNull() || dataObject.value("domain").isUndefined())
{
qDebug() << "SOmething went wrong";
throw malformedJSONException("[Article] domain");
}
qDebug() << "Added domain key to data object";
articleMetaData.domain = dataObject.value("domain").toString();if(dataObject.value("subreddit").isNull() || dataObject.value("subreddit").isUndefined())
{
throw malformedJSONException("[Article] subreddit");
}articleMetaData.subreddit = dataObject.value("subreddit").toString();
if(dataObject.value("selftext_html").isNull() || dataObject.value("selftext_html").isUndefined())
{
throw malformedJSONException("[Article] selftext_html");
}articleMetaData.selftextHTML = dataObject.value("selftext_html").toString();
if(dataObject.value("selftext").isNull() || dataObject.value("selftext").isUndefined())
{
throw malformedJSONException("[Article] selftext");
}articleMetaData.selfText = dataObject.value("selftext").toString();
if(dataObject.value("likes").isNull() || dataObject.value("likes").isUndefined())
{
throw malformedJSONException("[Article] likes");
}articleMetaData.likes = dataObject.value("likes").toDouble();
if(dataObject.value("id").isNull() || dataObject.value("id").isUndefined())
{
throw malformedJSONException("[Article] id");
}articleMetaData.id = dataObject.value("id").toString();
if(dataObject.value("stickied").isNull() || dataObject.value("stickied").isUndefined())
{
throw malformedJSONException("[Article] stickied");
}articleMetaData.stickied = dataObject.value("stickied").toBool();
if(dataObject.value("title").isNull() || dataObject.value("title").isUndefined())
{
throw malformedJSONException("[Article] title");
}articleMetaData.title = dataObject.value("title").toBool();
if(dataObject.value("score").isNull() || dataObject.value("score").isUndefined())
{
throw malformedJSONException("[Article] score");
}articleMetaData.score = dataObject.value("score").toDouble();
if(dataObject.value("over_18").isNull() || dataObject.value("over_18").isUndefined())
{
throw malformedJSONException("[Article] over_18");
}articleMetaData.over18 = dataObject.value("over_18").toBool();
if(dataObject.value("hidden").isNull() || dataObject.value("hidden").isUndefined())
{
throw malformedJSONException("[Article] hidden");
}articleMetaData.hidden = dataObject.value("hidden").toBool();
if(dataObject.value("subreddit_id").isNull() || dataObject.value("subreddit_id").isUndefined())
{
throw malformedJSONException("[Article] subreddit_id");
}articleMetaData.subredditID = dataObject.value("subreddit_id").toString();
if(dataObject.value("downs").isNull() || dataObject.value("downs").isUndefined())
{
throw malformedJSONException("[Article] downs");
}articleMetaData.downs = dataObject.value("downs").toDouble();
if(dataObject.value("saved").isNull() || dataObject.value("saved").isUndefined())
{
throw malformedJSONException("[Article] saved");
}articleMetaData.saved = dataObject.value("saved").toBool();
if(dataObject.value("is_self").isNull() || dataObject.value("is_self").isUndefined())
{
throw malformedJSONException("[Article] is_self");
}articleMetaData.isSelf = dataObject.value("is_self").toBool();
if(dataObject.value("permalink").isNull() || dataObject.value("permalink").isUndefined())
{
throw malformedJSONException("[Article] permalink");
}articleMetaData.permalink = dataObject.value("permalink").toString();
if(dataObject.value("name").isNull() || dataObject.value("name").isUndefined())
{
throw malformedJSONException("[Article] name");
}articleMetaData.name = dataObject.value("name").toString();
if(dataObject.value("created").isNull() || dataObject.value("created").isUndefined())
{
throw malformedJSONException("[Article] created");
}articleMetaData.created = dataObject.value("created").toDouble();
if(dataObject.value("created_utc").isNull() || dataObject.value("created_utc").isUndefined())
{
throw malformedJSONException("[Article] created_utc");
}articleMetaData.createdUTC = dataObject.value("created_utc").toDouble();
if(dataObject.value("ups").isNull() || dataObject.value("ups").isUndefined())
{
throw malformedJSONException("[Article] ups");
}articleMetaData.ups = dataObject.value("ups").toDouble();
qDebug() << "Parse Meta Article";
getNonEssentialElements(dataObject);
//test();
}
@The first if statement is throwing an exception. I don't understand why that is causing an error though. I caught and dealt with the error here:
@
int Subreddit::createArticles(QJsonArray &data)
{
QJsonArray::iterator iter;
for(iter = data.begin(); iter != data.end(); iter++){
QJsonObject articleObj = (*iter).toObject();
QJsonObject articleData = articleObj.value("data").toObject();
try
{
std::shared_ptr<Article> ptr( new Article(articleData.value("url").toString()));
articles.push_back((ptr));
break;
}catch(malformedJSONException& e) { qDebug() << e.what() << " " << e.key; } } qDebug() << "Done creating Articles";
}
@ -
I see the problem then: the short answer is: avoid the use of exceptions when using Qt. Or do it like "this":http://qt-project.org/doc/qt-5.0/qtdoc/exceptionsafety.html