[Interest] QObject::connect returns true, but the, connection does not work

Roland Hughes roland at logikalsolutions.com
Sat Feb 25 22:14:35 CET 2017


I am not having trouble with my program. I offered this up trying to 
point out where many people go wrong with console apps.

Gotten quite a few private messages on this matter and thankfully you 
included the list so I can reply to everyone.


On 02/25/2017 02:41 PM, Ch'Gans wrote:
> On 26 February 2017 at 06:09, Roland Hughes <roland at logikalsolutions.com> wrote:
>> Stupid question, but is this a console app?
>>
>> I'm asking because this happens with console apps. It can happen with any
>> app, but console apps tend to have the problem most often. Here is what I
>> mean:
>>
>> #include <QCoreApplication>
>> #include <QDebug>
>> #include <QTimer>
>>
>> #include "consoleinput.h"
>>
>> int main(int argc, char *argv[])
>> {
>>      QCoreApplication a(argc, argv);
>>      ConsoleInput console;
>>      bool b = a.connect(&console, &ConsoleInput::quit, &a,
>> &QCoreApplication::quit);
>>      qDebug() << "result of connect " << b;
>>
>>      QTimer::singleShot(0, &console, &ConsoleInput::run);
>>
>>      return a.exec();
>>
>> }
>>
>> If you do not use a QTimer to launch the console input method so it runs
>> from within the exec() loop, i.e. replace the QTimer line with
>>
>> console.run();
>>
>> Your connect call will return true but the signal will never trigger the
>> slot because execution is occurring outside of an event loop.
> connect() returns true, simply means that the connection has been
> made, if your concole.run() doesn't run an event loop no signal/slot
> will work AFAIK.
>
> Put a break point in ConsoleInput::quit() and check the call stack
> with the debugger to understand how this works.
>
> Chris
>
>> --
>>
>> Roland Hughes, President
>> Logikal Solutions
>>
>> http://www.theminimumyouneedtoknow.com
>> http://www.infiniteexposure.net
>> http://www.johnsmith-book.com
>> http://www.logikalblog.com
>> http://www.interestingauthors.com/blog
>> http://lesedi.us/
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest

-- 
Roland Hughes, President
Logikal Solutions
(630)-205-1593

http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com
http://www.logikalblog.com
http://www.interestingauthors.com/blog
http://lesedi.us/




More information about the Interest mailing list