Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal slot crash with static object
QtWS25 Last Chance

Signal slot crash with static object

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved