Results 1 to 20 of 33

Thread: Signal can't be emitted !

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Signal can't be emitted !

    Hello,

    file1.h
    Qt Code:
    1. class MyServer : public QTcpServer
    2. {
    3. Q_OBJECT
    4.  
    5. .... // some code
    6.  
    7. signals:
    8. void _connection(int);
    9.  
    10. .... // rest of the code
    To copy to clipboard, switch view to plain text mode 


    file1.cpp
    Qt Code:
    1. void MyServer::incomingConnection(int handle)
    2. {
    3. MyClient *client = new MyClient(this);
    4. client->setsocket(handle);
    5. emit _connection(handle); // i emit it here
    6. }
    To copy to clipboard, switch view to plain text mode 

    file2.h
    Qt Code:
    1. #include "file1.h"
    2. class Blabla: public QObject
    3. {
    4. Q_OBJECT
    5.  
    6. ... // code here
    7.  
    8. private:
    9. MyServer *server;
    10.  
    11. ... // rest of code
    To copy to clipboard, switch view to plain text mode 

    file2.cpp
    Qt Code:
    1. server = new MyServer;
    2.  
    3. connect(server,SIGNAL(_connection()), this, SLOT(connected())); // the slot is declared in the code
    To copy to clipboard, switch view to plain text mode 

    The issue:
    ----------
    The signal is not emitted within the incoming connction.

    The question:
    -------------
    Why ?


    Thanks,
    Vladimir.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Signal can't be emitted !

    The code is never called. You are not running the code you think you are. You have not connected to the signal or object you think you have. There is no incoming connection, perhaps blocked by a firewall. Etc.

    What have you done to debug this? Put a breakpoint in the routine? Single stepped?

  3. #3
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    there's an incoming connection,

    Qt Code:
    1. void MyServer::incomingConnection(int handle)
    2. {
    3. MyClient *client = new MyClient(this);
    4. client->setsocket(handle);
    5. QMessageBox::information(0, "connected", "new client"); // this runs, so the function worked.
    6. emit _connection(handle); // i emit it here
    7. }
    To copy to clipboard, switch view to plain text mode 

    the incomingConnection() is written in italic in the QtCreator. it's already coded.

    here's a proof that the code worked:
    000000000000000000000000000000000000000000000000000000000.png

    but the signal is never emitted.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal can't be emitted !

    How do you know the signal is not emitted? Maybe a more appropriate topic to your problem would be "slot is not called" rather than "signal is not emitted"? Can you call connected() using e.g. invokeMethod()? Do the sender and receiver belong to the same thread?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    I used another signal, and the slot is called.

    So i made sure that the slot has no issues .

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal can't be emitted !

    Is the connection established properly? Does connect() return true? Do you get any messages, warnings on the console when your program is running?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    no messages or warnings at all !

    the connection istablished well, and i even get the sent data via QByteArray and display it in QMessageBox.

    only this can't be emitted !!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal can't be emitted !

    Quote Originally Posted by Vladimir_ View Post
    no messages or warnings at all !
    I'm sure you are wrong about this. Maybe you are looking in the wrong place. We are talking about a runtime message to the console, not a warning during compilation.

    the connection istablished well
    Does connect() return true? I don't think so.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal can't be emitted !

    connect() returns 0 , means "false" ....

    What an I do now ?!

    i posted all the codes I did, i need it working

    Quote Originally Posted by anda_skoa View Post
    The signal is not emitted because it does not exists.
    see file1.h and file1.cpp .

    what do you mean it does not exist ?

  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal can't be emitted !

    1. Is the class with method connected() derived from QObject ?
    2. Is the method connected declared as slot ?

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal can't be emitted !

    Quote Originally Posted by Vladimir_ View Post
    file2.cpp
    Qt Code:
    1. server = new MyServer;
    2.  
    3. connect(server,SIGNAL(_connection()), this, SLOT(connected())); // the slot is declared in the code
    To copy to clipboard, switch view to plain text mode 

    The issue:
    ----------
    The signal is not emitted within the incoming connction.
    The signal is not emitted because it does not exists.

    The application output would have told you that (Qt prints a warning) and the return value of the connect would have been "false".

    Look at the content of the SIGNAL macro and the declaration of the signal and find the difference.

    Cheers,
    _


    P.S.: unless you need SSL sockets, there is no need to derive from QTcpServer. I has a signal that is emitted for each incoming connection.

Similar Threads

  1. Signal isn't emitted from socket
    By 8Observer8 in forum Newbie
    Replies: 3
    Last Post: 14th August 2013, 13:33
  2. loadFinished() signal not emitted
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 27th June 2013, 12:21
  3. QTcpSocket error signal emitted twice
    By CactusPie in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2013, 15:54
  4. signal emitted when I zoom
    By mastupristi in forum Qwt
    Replies: 1
    Last Post: 8th July 2009, 17:02
  5. Signal emitted more than once?
    By dbrmik in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2009, 12:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.