Results 1 to 8 of 8

Thread: Slot doesn't get called

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

    Default Slot doesn't get called

    This should be simple, but I don't see it.
    Trying to emit a signal in the EditLog class to call a slot in the MainWindow.
    No error, but the slot doesn't get called.

    the EditLog.h entries:
    Qt Code:
    1. signals:
    2. void logChanged();
    3.  
    4. private slots:
    5. void on_pbSave_clicked();
    6. void on_pbCancel_clicked();
    To copy to clipboard, switch view to plain text mode 

    the EditLog cpp
    Qt Code:
    1. void EditLog::on_pbSave_clicked()
    2. {
    3. // some code
    4. emit logChanged();
    To copy to clipboard, switch view to plain text mode 

    the MainWindow.h
    Qt Code:
    1. public slots:
    2. void updateLogView();
    To copy to clipboard, switch view to plain text mode 

    the MainWindow.cpp // updateLogView never gets executed
    Qt Code:
    1. // in the constructor:
    2. EditLog el;
    3. connect(&el, SIGNAL(logChanged()), this, SLOT(updateLogView()));
    4. //
    5. void MainWindow::updateLogView() {
    6. view->selectionModel()->clearSelection();
    7. model->select();
    8. view->resizeColumnsToContents();
    9. qDebug() << "edit model error is " << model->lastError();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Any idea what I am missing?
    Last edited by waynew; 17th April 2010 at 23:01. Reason: Forgot some code

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slot doesn't get called

    What does the output window say?

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

    Default Re: Slot doesn't get called

    I have a debug after the emit and it displays ok. The edit model debug message does not display.
    So that and the fact that the view does not show the changed data lead me to believe that the updateLogView function is not being called.
    Thanks for responding Mole - do you see anything I am doing wrong or have left out? Something is definitely not right.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Slot doesn't get called

    Hi Waynew,

    Try creating your EditLog on the heap.

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

    Default Re: Slot doesn't get called

    Ok, I tried this:
    Qt Code:
    1. EditLog *el = new EditLog;
    2. connect(el, SIGNAL(logChanged()), this, SLOT(updateLogView()));
    To copy to clipboard, switch view to plain text mode 

    Same results.

  6. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Slot doesn't get called

    The code you've posted looks okay to me. I created a project that is a crude approximation of what you are doing and got no errors but the slot is not called if created on the stack. Works fine created on the heap.
    Attached Files Attached Files

  7. The following user says thank you to norobro for this useful post:

    waynew (18th April 2010)

  8. #7
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slot doesn't get called

    Thanks for going to all of that trouble Norobro. I'll check it out and see what I can figure out. Will post later.

  9. #8
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Slot doesn't get called

    Ok, working now thanks to your help. I believe the problem I had was 2 instantiations of EditLog. One for the signal and one where I had to call the edit function. Fixed that and it gets the signal fine now.

Similar Threads

  1. How come this slot doesn't get called every second?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 23:41
  2. Replies: 0
    Last Post: 17th September 2009, 10:40
  3. Slot gets called twice
    By greatgatsby in forum Newbie
    Replies: 7
    Last Post: 20th August 2009, 15:11
  4. commitData doesn't seem to be called...
    By tone in forum Qt Programming
    Replies: 7
    Last Post: 10th September 2008, 14:42
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 11:30

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.