Results 1 to 4 of 4

Thread: C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

    Hello,

    A follow on to this post of mine.
    http://www.qtcentre.org/threads/6695...dow-to-QDialog

    I've progressed a little, thanks to your help.
    Another problem.
    I'm emitting a signal early in the noobsForm init process, which is not getting called.
    I've read somewhere that signals and slots are set up sometime in the process but are not guaranteed when.
    I added a process events call, no help.
    Is this my problem? If it is, is there any round it?

    Regards
    Qt Code:
    1. mainwindow.cpp
    2. noobsForm myNoobs(listPart, file);
    3.  
    4. QObject::connect(&myNoobs, SIGNAL(doFormat(int, bool)),
    5. this, SLOT(formatSDcard(int, bool)));
    6. QObject::connect(&myNoobs, SIGNAL(doWriteNoobs(int, bool, QString)),
    7. this, SLOT(writeNoobs(int, bool, QString)));
    8. QObject::connect(&myNoobs, SIGNAL(doUpdateDriveDataList()),
    9. this, SLOT(getLogicalDrivesSlot()));
    10. ****
    11. QObject::connect(&myNoobs, SIGNAL(doGetFileCount(QString)),
    12. this, SLOT(getUpdatedFileCount(QString)));
    13. ****
    14. myNoobs.exec();
    15.  
    16. void MainWindow::getUpdatedFileCount(QString driveLetter) //slot
    17. {
    18. qDebug() << "getupdatedfilecountSlot" << driveLetter;
    19. //getFileList(driveLetter);
    20. //qDebug() << countFiles << "-" << countDirs;
    21. //emit doUpdateFileList(countFiles, countDirs);
    22. }
    23.  
    24. mainwindow.hpp
    25. public slots:
    26. bool formatSDcard(int type, bool remote);
    27. void writeNoobs(int which, bool remote, QString file);
    28. void getLogicalDrives(); // find attached USB devices
    29. void getUpdatedFileCount(QString driveLetter);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. noobsForm.cpp
    2. This is in the noobsForm init process:-
    3. delay(1000); //process events - ? required
    4. qDebug() << "passed letter" << (driveLetter + ":");
    5. emit doGetFileCount(driveLetter + ":");
    6.  
    7. These are triggered by pushbuttons and work:-
    8. emit doFormat(type, true);
    9. emit doWriteNoobs(1, true, address);
    10. emit doUpdateDriveDataList();
    11.  
    12. noobs.hpp
    13. signals:
    14. void doFormat(int, bool);
    15. void doWriteNoobs(int, bool, QString);
    16. void doUpdateDriveDataList();
    17. void doGetFileCount(QString);
    18.  
    19. Debug output:-
    20. passed letter "J:"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

    What does it mean I'm emitting a signal early in the noobsForm init process ? Is the init process is the constructor ?

  3. #3
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

    Hello Lesiok,

    Thanks for your response.
    Is the init process is the constructor ?
    No.
    Qt Code:
    1. noobsForm::noobsForm(QStringList passedDataList, QString fileName,
    2. QWidget *parent) : QDialog(parent),
    3. ui(new Ui::noobsForm)
    4. {
    5. ...
    6. ...
    7. initInst();
    8. }
    9.  
    10. void noobsForm::initInst()
    11. {
    12. ...
    13. ...
    14. delay(1000); //process events
    15. qDebug() << "passed letter" << (driveLetter + ":");
    16. emit doGetFileCount(driveLetter + ":");
    17. ...
    18. ...
    19. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

    How not like yes ? initInst() is called from constructor. Signals are connected after them so what are you surprised that it does not work ?
    Maybe you should first learn the basics of C++.

Similar Threads

  1. QSslSocket: connecting SIGNAL and SLOT
    By Mobility in forum Qt Programming
    Replies: 14
    Last Post: 1st January 2013, 17:59
  2. Connecting custom signal and slot
    By DmitryNik in forum Newbie
    Replies: 4
    Last Post: 12th September 2011, 14:15
  3. Connecting signal and slot by name
    By grayfox in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 09:00
  4. Replies: 3
    Last Post: 17th November 2010, 14:12
  5. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28

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.