Results 1 to 4 of 4

Thread: Signal and Slot Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Signal and Slot Problem

    Just when I thought I had signals and slots figured out ... not so.
    I have one class (editlog) that sends a signal to a slot in the mainwindow, and it works fine.
    So I set up another one from a different class (openlog), and ... nothing, no response.

    Here is the code that works ok:

    Qt Code:
    1. // part of editlog.h
    2. signals:
    3. void addLookup(int);
    4.  
    5. // part of editlog.cpp
    6. void EditLog::on_pushButton_clicked()
    7. {
    8. emit addLookup(::logID);
    9. }
    10.  
    11. // part of mainwindow.h
    12. public:
    13. EditLog *el;
    14.  
    15. public slots:
    16. void updateLog(int);
    17.  
    18. // part of mainwindow.cpp
    19.  
    20. el = new EditLog;
    21. // Signal connection from EditLog class
    22. connect(el, SIGNAL(addLookup(int)), this, SLOT(updateLog(int)));
    23.  
    24. void MainWindow::updateLog(int newID)
    25. {
    26. // code updates log ok
    27. }
    To copy to clipboard, switch view to plain text mode 

    Here is the code that seems to do nothing:
    Qt Code:
    1. // part of openlog.h // this is a dialog
    2.  
    3. signals:
    4. void callOpenLog(QString);
    5.  
    6. // part of openlog.cpp
    7.  
    8. void OpenLog::on_pbOpen_clicked()
    9. {
    10. QString openLog = ui->cbLogName->currentText();
    11. emit callOpenLog(openLog);
    12. close(); // the dialog window
    13. }
    14.  
    15. // part of mainwindow.h
    16. public:
    17. OpenLog *ol;
    18.  
    19. // part of mainwindow.cpp
    20. ol = new OpenLog;
    21. connect(ol, SIGNAL(callOpenLog(QString)), this, SLOT(openLog(QString)));
    22.  
    23. void MainWindow::openLog(QString logName) // never called
    24. {
    25. // code would open the log if the signal was received
    26. }
    To copy to clipboard, switch view to plain text mode 

    Could this have something to do with the fact that the signal from the class that works comes from a dialog window that does not get closed after the signal is sent and the one that does not work comes from a dialog class where the window gets closed right after the signal is sent. If so, how to make it work? Or what else is wrong?
    Last edited by waynew; 5th June 2010 at 01:12. Reason: code error

Similar Threads

  1. signal / slot problem
    By franco.amato in forum Newbie
    Replies: 13
    Last Post: 8th December 2009, 18:10
  2. Problem with New Slot/Signal in QTDesigner4.4.3
    By durgarao in forum Qt Tools
    Replies: 1
    Last Post: 27th December 2008, 12:39
  3. signal-slot problem with QVector
    By stefan in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 13:58
  4. problem with signal/slot mechanismus
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 7th March 2008, 19:05
  5. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59

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
  •  
Qt is a trademark of The Qt Company.