Signal slot crash with static object



  • Hi,

    I wanted to interface my Qt class in a "C" application. For that I have created static object in my application as follows. When the code start execution, it constructs "MyQtClass", and in this construtor the code crashes at the "connect" call!! I think the following code would be more readable than my explanation.

    @
    class MyQtClass:public QTcpSocket
    {
    Q_OBJECT
    public:
    MyQtClass(QObject *parent=0);
    ~MyQtClass();
    bool Connect(QHostAddress addr,quint16 port);
    private slots:
    void MySlot(QAbstractSocket::SocketState);
    };

    MyQtClass::MyQtClass(QObject *parent):QTcpSocket(parent)
    {
    //executing this line causes a crash
    connect(this,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(MySlot(QAbstractSocket::SocketState)));
    }

    extern "C"
    {
    static MyQtClass comm;
    int Connect(char* host, unsigned short port)
    {
    return comm.Connect(QHostAddress(host),port);
    }
    }

    @

    What is the reason for crash?

    Thanks,
    Lloyd



  • What crash? Once I provide and empty implementation for the missing destructor, slot,and Connect() function and a do nothing main() the code compiles and runs without error.

    You need to rebuild the program am run it in a debugger. When it crashes look at the backtrace to find out what is causing it to die.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.