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. Differences from two connect declaration
Forum Updated to NodeBB v4.3 + New Features

Differences from two connect declaration

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 531 Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Andrew74
    wrote on last edited by
    #1

    Hi
    I'm novice in QT world, and I found a very strange problem (for me) about connect declaration. I've created SIGNAL and SLOT custom in my class, and if I use:

    connect(socket, SIGNAL(disconnectedCustom()), this, SLOT(myDisconnection()));
    

    When code run my program crash and in debug I see:

    c:\users\qt\work\qt\qtbase\src\corelib\tools\qscopedpointer.h:140: error: Debugger encountered an exception: Exception at 0x7ffef8222d4a, code: 0xc0000005: read access violation at: 0xffffffffffffffff, flags=0x0 (first chance)
    

    But, if remove previous line and I write:

    connect(socket,&mySocket::disconnectedCustom, this, &MyTcpServer::myDisconnection);
    

    It works fine (socket is an instance of mySocket, and this is MyTcpServer). socket is created with new:

    mySocket *socket = new mySocket(server->nextPendingConnection()); // serve is QTcpServer instance.
    

    I thought (wrongly) that the two previous lines did the same thing, but obviously I'm wrong. Can someone explain to me what is wrong with the first line?

    Thanks (and sorry for my bad english).

    K 1 Reply Last reply
    0
    • A Andrew74

      Hi
      I'm novice in QT world, and I found a very strange problem (for me) about connect declaration. I've created SIGNAL and SLOT custom in my class, and if I use:

      connect(socket, SIGNAL(disconnectedCustom()), this, SLOT(myDisconnection()));
      

      When code run my program crash and in debug I see:

      c:\users\qt\work\qt\qtbase\src\corelib\tools\qscopedpointer.h:140: error: Debugger encountered an exception: Exception at 0x7ffef8222d4a, code: 0xc0000005: read access violation at: 0xffffffffffffffff, flags=0x0 (first chance)
      

      But, if remove previous line and I write:

      connect(socket,&mySocket::disconnectedCustom, this, &MyTcpServer::myDisconnection);
      

      It works fine (socket is an instance of mySocket, and this is MyTcpServer). socket is created with new:

      mySocket *socket = new mySocket(server->nextPendingConnection()); // serve is QTcpServer instance.
      

      I thought (wrongly) that the two previous lines did the same thing, but obviously I'm wrong. Can someone explain to me what is wrong with the first line?

      Thanks (and sorry for my bad english).

      K Offline
      K Offline
      koahnig
      wrote on last edited by koahnig
      #2

      @Andrew74

      Hi and welcome to devnet forum

      There should be no difference performance- or stability-wise with the different version of connect you have tried.
      The first version is the older macro based version, which will tell you only during prcoessing that there might be problem (e.g. signal or slot missing). However, it should not cause a crash.

      The second form is newer and hasthe advantage of giving a compile error when something in the declaration or elsewhere is wrong. Personally I see the benefit there because you do not have to wait until the signal is issued, because the warnings with the older version are often hidden by additional output and therefore not seen.

      Most likely there some sort of change in source not properly compiled and linked, which caused the crash. If you are interested you may want to change back to macro based version for sanity check.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Andrew74
        wrote on last edited by
        #3

        Hi koahnig, thanks for the reply. I refactored all my code (after more test and code) and now I use new method to connect signal and slot. Now it works fine - I think the previous problem was due to my inexperience.

        K 1 Reply Last reply
        0
        • A Andrew74

          Hi koahnig, thanks for the reply. I refactored all my code (after more test and code) and now I use new method to connect signal and slot. Now it works fine - I think the previous problem was due to my inexperience.

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Andrew74

          You are welcome.

          We all have to start somewhere in the beginning not everything is logic until the pieces of the puzzle falling into place.

          Enjoy programming with Qt

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1

          • Login

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