Important: Please read the Qt Code of Conduct -

QtCreator QSimulate tutorial - Part 8

  • So, I got through Part 7 just fine, then added the recommended code, creating new header files and making enhancements to some of the .cpp files. When I run, I am seeing a seg fault as soon as i elft mouse button click in the simulator panel. So, I tried using the
    debugger and have traced it to the setText() call in commandstationadd.h (called from scene.cpp - m_undostack->push( new CommandStationAdd(this, x, y)); ).

    BTW, if I use the Part 7 implementation and call addItem() instead, there's no issue with the left mouse button click.

    I stepped into qchar.h in the QLatinChar struct, where char c is 32 ' ' as displayed in the Value column in the debugger. Stepping into the inline explicit for QLatin1Char leads to the #else clause which wants to return ushort(uchar(ch));.

    @inline QChar::QChar(QLatin1Char ch) : ucs(ch.unicode()) {}@

    @ inline char toLatin1() const { return ch; }
    inline ushort unicode() const { return ushort(uchar(ch)); }

    Then off to qstring.h:

    @#ifndef QT_NO_CAST_FROM_ASCII
    inline QT_ASCII_CAST_WARN_CONSTRUCTOR QString(const char *ch) : d(fromAscii_helper(ch))


    @inline QString::~QString() { if (!d->ref.deref()) free(d); }@

    Then qatomic_i386.h

    @inline bool QBasicAtomicInt::deref()
    unsigned char ret;
    asm volatile("lock\n"
    "decl %0\n"
    "setne %1"
    : "=m" (_q_value), "=qm" (ret)
    : "m" (_q_value)
    : "memory");
    return ret != 0;

    where ret is: 8, still single stepping, we're back there again and ret is now 1, the 0 which shows '\0', then back in again and ret is now 191 (in red, no less), the 0 '\0' again and we finally end up with the seg fault.

  • What did you do?

Log in to reply