PDA

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



jimbo
19th October 2016, 15:23
Hello,

A follow on to this post of mine.
http://www.qtcentre.org/threads/66953-Qt5-C-Signals-and-slots-QMainwindow-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

mainwindow.cpp
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)));
****
myNoobs.exec();

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

mainwindow.hpp
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);
noobsForm.cpp
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();

noobs.hpp
signals:
void doFormat(int, bool);
void doWriteNoobs(int, bool, QString);
void doUpdateDriveDataList();
void doGetFileCount(QString);

Debug output:-
passed letter "J:"

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

jimbo
19th October 2016, 15: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)
{
...
...
initInst();
}

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

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