Serguei Kalentchouk
Serguei Kalentchouk

Reputation: 190

QStringList.append() crash on OS X

I am running into a really odd crash on OS X with Qt 4.8.6.

I have a very simple bit of code (which works just fine in our Windows and Linux builds):

QStringList list;
list << "test";

What I'm finding is that the append operation will crash at runtime with the following stack trace:

QBasicAtomicInt::ref() { asm volatile("lock\n" ... }
QString::QString(QString const&)
QString::QString(QString const&)
QList<QString>::node_copy(QList<QString>::Node*from, QList<QString>::Node*, QList<QString>::Node*)
QList<QString>::detach_helper_grow(int, int)
QList<QString>::append(QString const&)
QStringList::operator<<(QString const&)

Most other operations including the destructor for QStringList lead to similar crash.

I'm really at a loss of how to debug this further, any advice would be greatly appreciated.

Thanks!

Upvotes: 1

Views: 795

Answers (2)

Serguei Kalentchouk
Serguei Kalentchouk

Reputation: 190

We finally tracked it down, turns out the Qt library we are linking against had modified the headers and our build system wasn't pulling them in correctly. I guess that's a lesson that its always best to trust but verify :)

Thanks for the help everyone!

Upvotes: 0

kintel
kintel

Reputation: 435

This looks like a typical case of the Qt library being built by a different compiler or linked by a different C++ library than the rest of your application. On OS X, the main culprit tends to be libstdc++ vs. libc++, which have incompatible string implementations, among other things.

Can you reproduce this with a trivial example?, e.g.:

qstringlist.pro:

SOURCES = qstringlist.cpp

qstringlist.cpp:

#include <QStringList>
#include <iostream>
int main(int argc, char *argv[]) {
  QStringList list;
  list << "test";
  std::cout << list.join(" ").toStdString() << std::endl;
}

..then qmake qstringlist.pro && make && ./qstringlist.app/Contents/MacOS/qstringlist

To get around this, I typically build Qt myself, with carefully chosen build settings if I want to run on other systems.

Upvotes: 1

Related Questions