View Full Version : C++/Qt 5.7 - QDialog to QMainWindow - signal not connecting to slot

19th October 2016, 14:23

A follow on to this post of mine.

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?


noobsForm myNoobs(listPart, file);

QObject::connect(&myNoobs, SIGNAL(doFormat(int, bool)),
this, SLOT(formatSDcard(int, bool)));
QObject::connect(&myNoobs, SIGNAL(doWriteNoobs(int, bool, QString)),
this, SLOT(writeNoobs(int, bool, QString)));
QObject::connect(&myNoobs, SIGNAL(doUpdateDriveDataList()),
this, SLOT(getLogicalDrivesSlot()));
QObject::connect(&myNoobs, SIGNAL(doGetFileCount(QString)),
this, SLOT(getUpdatedFileCount(QString)));

void MainWindow::getUpdatedFileCount(QString driveLetter) //slot
qDebug() << "getupdatedfilecountSlot" << driveLetter;
//qDebug() << countFiles << "-" << countDirs;
//emit doUpdateFileList(countFiles, countDirs);

public slots:
bool formatSDcard(int type, bool remote);
void writeNoobs(int which, bool remote, QString file);
void getLogicalDrives(); // find attached USB devices
void getUpdatedFileCount(QString driveLetter);
This is in the noobsForm init process:-
delay(1000); //process events - ? required
qDebug() << "passed letter" << (driveLetter + ":");
emit doGetFileCount(driveLetter + ":");

These are triggered by pushbuttons and work:-
emit doFormat(type, true);
emit doWriteNoobs(1, true, address);
emit doUpdateDriveDataList();

void doFormat(int, bool);
void doWriteNoobs(int, bool, QString);
void doUpdateDriveDataList();
void doGetFileCount(QString);

Debug output:-
passed letter "J:"

19th October 2016, 14:31
What does it mean I'm emitting a signal early in the noobsForm init process ? Is the init process is the constructor ?

19th October 2016, 14:44
Hello Lesiok,

Thanks for your response.

Is the init process is the constructor ?No.

noobsForm::noobsForm(QStringList passedDataList, QString fileName,
QWidget *parent) : QDialog(parent),
ui(new Ui::noobsForm)

void noobsForm::initInst()
delay(1000); //process events
qDebug() << "passed letter" << (driveLetter + ":");
emit doGetFileCount(driveLetter + ":");

19th October 2016, 15:07
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++.