PDA

View Full Version : c++/Qt5 Signals and slots



jimbo
15th February 2016, 16:52
Hello,

I'm porting 'Ext2Explore' to Qt5 from Qt4 so I can use parts of it in my program.
I have one last problem.
I need to generate a dblClicked signal for the 'tree' and 'list', but
do not understand the syntax required.
The program compiles with no errors.
When compiled for Release it crashes.
When compiled for Debug, generates the following error/warning.

QMetaObject::connectSlotsByName: No matching signal for on_action_item_dbclicked(QModelIndex)
Can someone help, please?

Regards

Ext2Explore::Ext2Explore(QWidget *parent) : QMainWindow(parent), ui(new Ui::Ext2Explore)
{
...
connect(ui->tree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_action_item_dbclicked(const QModelIndex &)));
connect(ui->list, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_action_item_dbclicked(const QModelIndex &)));
}

void Ext2Explore::on_action_item_dbclicked(const QModelIndex &index) //slot
{
...
}

private slots:
void on_action_item_dbclicked(const QModelIndex &index);

signals:
//This is where I have no idea??

anda_skoa
15th February 2016, 23:26
You can probably ignore that warning.

The on_something syntax and the "connect by name" comes from the "auto connect" feature that some people use for convenience.
I.e. a slot named with on_ followed by the object name of a UI element followed by the name of a signal on that object will bet attempted to be connected automatically.

This is often used by beginners because some tutorials on the Internet do that inspite of being a terrible idea.

You, on the other hand, have explicit connects. What you could do to avoid the warnining is to rename your slots so that they don't match the pattern anymore.
E.g onActionItemDoubleClicked()

Cheers,
_

jimbo
16th February 2016, 11:18
Hello anda_skoa,

Thanks for that, got rid of the Debug compile warning.
But!
Compiled for Release, when I start the program I get:-
'The program has unexpectedly finished.'

Any suggestions as to where to start finding the reason for this?

Regards

anda_skoa
16th February 2016, 11:50
If you run the program in the debugger, it should display the call stack trace leading up to the crash.

Very often such crashes are caused by access to uninitialized pointers.

Cheers,
_

ChrisW67
16th February 2016, 12:51
The message about "no matching signal" is a bit odd, as the thing it is complaining about is a slot. You need to ensure that qmake has run moc over the HEADERS. Also, this code:

connect(ui->tree, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(on_action_item_dbclicked(const QModelIndex &)));
connect(ui->list, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(on_action_item_dbclicked(const QModelIndex &)));

Should probably read


connect(ui->tree, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(on_action_item_dbclicked(QModelIndex)));
connect(ui->list, SIGNAL(doubleClicked(QModelIndex)),
this, SLOT(on_action_item_dbclicked(QModelIndex)));

jimbo
16th February 2016, 17:30
Hello,

Thanks to all who have made suggestions.

Curiouser and Curiouser (said Alice).

I pulled the release .exe to a folder on the desktop, added the required .dlls and the program ran fine.
I wonder if my Qt installation has got screwed.

Before I reinstall Qt, I will try your suggestions.

I ran the program in the debugger and got a popup:-
Executable Failed
'During startup program exited with code 0xc0000135.'

Regards

d_stranz
16th February 2016, 19:31
'During startup program exited with code 0xc0000135.'


A quick google search indicates that this is due to a missing .NET framework. If your release mode exe runs fine, then it probably means you are missing the debug DLLs for the framework. These should have been installed with your copy of the Microsoft compilers, but if not you may have to look around for a download. No idea which of the many versions of .NET framework this could be though.

ChrisW67
16th February 2016, 20:19
The c0000135 error is a generic "DLL not found" error, not something specific to .Net. Given that you clearly have the DLLs present on your system somewhere it seems likely that the environment (mainly PATH) being given to your project when run is missing directories containing matching third-party libraries.

jimbo
16th February 2016, 22:54
Hello ChrisW67 and d_stranz,

I've already checked the error code to see what it ment.
I installed Dependecy Walker and it shows up a lot of missing .dlls.
I think I will have to check the source againts a fresh download of ext2explorer.
I recompiled an old project of mine and everything was OK, so Qt is fine.
More testing tomorrow.

Regards

jimbo
19th February 2016, 07:48
Hello,

Thanks to everybody that helped.

I replaced the hard drive, bak ups and reinstalled some software , everything is fine.
I'm guessing it was something to do with paths and a dodgy hard drive.

Rgards