Qt-interest Archive, October 2007
Who is the sender of a static signal?
Message 1 in thread
ALL,
I have a static signal showShring():
class DlgExt : public QObject
{
Q_OBJECT
public:
DlgExt();
signals:
static void showString(const QString &s);
};
A static function can be called without instantiating the class.
However, when I try to connect the signal to a lot, I need a sender.
Who is the sender, or what is the sytax of QObject::connect()?
Thanks,
Lingfa
--
[ signature omitted ]
Message 2 in thread
On 10/1/07, Lingfa Yang <lingfa@xxxxxxx> wrote:
> A static function can be called without instantiating the class.
> However, when I try to connect the signal to a lot, I need a sender.
> Who is the sender, or what is the sytax of QObject::connect()?
You can't have static signals. It's probably best if you explain what
you're trying to achieve as you may well be able to get the effect you
want by some other means.
Rich.
--
[ signature omitted ]
Message 3 in thread
Richard Moore wrote:
>On 10/1/07, Lingfa Yang <lingfa@xxxxxxx> wrote:
>
>
>>A static function can be called without instantiating the class.
>>However, when I try to connect the signal to a lot, I need a sender.
>>Who is the sender, or what is the sytax of QObject::connect()?
>>
>>
>
>You can't have static signals. It's probably best if you explain what
>you're trying to achieve as you may well be able to get the effect you
>want by some other means.
>
>Rich.
>
>
>
Rich,
I am making a library. Very often I use qDebug() << to show some
message. Now I am sick of qDebug, I wish to unify the output to a status
bar, or a textEdit window.
Because this is a library, it does know how the application will handle
the message.
My wish is a sttic signal:
emit DlgExt::showString(msg); // a static signal
Then, by specifying slot, these messages go to different place to
display, for examples,
connect(sender, SIGNAL(showString(const QString &)), app1,
SLOT(displayOnStatusBar(const QString &)));
or
connect(sender, SIGNAL(showString(const QString &)), app2,
SLOT(displayInTextEditWindow(const QString &)));
Then, question comes who is the sender?
If I cannot have static signals, how can I uniformly output these messages?
Thanks
Lingfa
--
[ signature omitted ]
Message 4 in thread
On 01.10.07 17:18:55, Lingfa Yang wrote:
> Richard Moore wrote:
>
> >On 10/1/07, Lingfa Yang <lingfa@xxxxxxx> wrote:
> >
> >>A static function can be called without instantiating the class.
> >>However, when I try to connect the signal to a lot, I need a sender.
> >>Who is the sender, or what is the sytax of QObject::connect()?
> >>
> >
> >You can't have static signals. It's probably best if you explain what
> >you're trying to achieve as you may well be able to get the effect you
> >want by some other means.
> >
> >Rich.
> >
> >
> Rich,
>
> I am making a library. Very often I use qDebug() << to show some message. Now I
> am sick of qDebug, I wish to unify the output to a status bar, or a textEdit
> window.
>
> Because this is a library, it does know how the application will handle the
> message.
> My wish is a sttic signal:
> emit DlgExt::showString(msg); // a static signal
>
> Then, by specifying slot, these messages go to different place to display, for
> examples,
> connect(sender, SIGNAL(showString(const QString &)), app1,
> SLOT(displayOnStatusBar(const QString &)));
> or
> connect(sender, SIGNAL(showString(const QString &)), app2,
> SLOT(displayInTextEditWindow(const QString &)));
>
> Then, question comes who is the sender?
Well, lets say you have a sender how do you think you can emit a signal?
I mean signals are protected functions, thus you'd have to have a
protected static member function inside that class that takes the
message and runs emit.
At that point you could as well use a singleton pattern for the DlgExt
class and have a member function like this
emitMessage( const QString& msg )
{
emit showString(msg);
}
Then you can use DlgExt::self() to do the connection.
Andreas
--
[ signature omitted ]
Message 5 in thread
>At that point you could as well use a singleton pattern for the DlgExt
>class and have a member function like this
>
>emitMessage( const QString& msg )
>{
> emit showString(msg);
>}
>
>Then you can use DlgExt::self() to do the connection.
>
>Andreas
>
>
>
Andreas
Yes, following your singleton I implemented the singleton:
// in *.h
class DlgExt : public QObject
{
Q_OBJECT
public:
static DlgExt *self();
void show(const QString &s);
signals:
void showMessage(const QString &s);
private:
DlgExt(){}; // private constructor
static DlgExt *dlgEdit;
};
// in MainWindow
connect(DlgExt::self(), SIGNAL(showMessage(const QString &)),
this, SLOT(insertComment(const QString &)));
// in other classes
DlgExt::self()->show( msg );
I like it. Thank you very much.
Regards,
Lingfa
--
[ signature omitted ]
Message 6 in thread
You can catch all the debugs in an easier way. And you won't have to
refactor all your debug code.
Install a function pointer to catch all the qDebug() messages with
qInstallMsgHandler().
Then you can do whatever you want with the messages. You can even be
creative and choose to output to a file in release and output to a
QTextEdit window at runtime.
Example straight out of assistant:
#include <qapplication.h>
#include <stdio.h>
#include <stdlib.h>
void myMessageOutput(QtMsgType type, const char *msg)
{
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", msg);
abort();
}
}
int main(int argc, char **argv)
{
qInstallMsgHandler(myMessageOutput);
QApplication app(argc, argv);
...
return app.exec();
}
--Justin
Lingfa Yang wrote:
> Richard Moore wrote:
>
>> On 10/1/07, Lingfa Yang <lingfa@xxxxxxx> wrote:
>>
>>
>>> A static function can be called without instantiating the class.
>>> However, when I try to connect the signal to a lot, I need a sender.
>>> Who is the sender, or what is the sytax of QObject::connect()?
>>>
>>
>> You can't have static signals. It's probably best if you explain what
>> you're trying to achieve as you may well be able to get the effect you
>> want by some other means.
>>
>> Rich.
>>
>>
>>
> Rich,
>
> I am making a library. Very often I use qDebug() << to show some
> message. Now I am sick of qDebug, I wish to unify the output to a
> status bar, or a textEdit window.
>
> Because this is a library, it does know how the application will
> handle the message.
> My wish is a sttic signal:
> emit DlgExt::showString(msg); // a static signal
>
> Then, by specifying slot, these messages go to different place to
> display, for examples,
> connect(sender, SIGNAL(showString(const QString &)), app1,
> SLOT(displayOnStatusBar(const QString &)));
> or
> connect(sender, SIGNAL(showString(const QString &)), app2,
> SLOT(displayInTextEditWindow(const QString &)));
>
> Then, question comes who is the sender?
> If I cannot have static signals, how can I uniformly output these
> messages?
> Thanks
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 7 in thread
Justin Noel wrote:
>
> You can catch all the debugs in an easier way. And you won't have to
> refactor all your debug code.
>
> Install a function pointer to catch all the qDebug() messages with
> qInstallMsgHandler().
>
> Then you can do whatever you want with the messages. You can even be
> creative and choose to output to a file in release and output to a
> QTextEdit window at runtime.
Justin,
I do not even know there is such a nice function, which is exactly what
I want.
Thank you very much for your helpful reply.
Regards,
Lingfa
--
[ signature omitted ]
Message 8 in thread
For what it's worth, we catch all errors reported by Qt in
qInstallMsgHandler and have them emailed to developers without notifying
the user.
This seems to work better than presenting users with scary messages.
Code below.
For a non-Qt error, the user is notified and given the option of
reporting (by email) the error, along with environment data.
Obviously you could do this differently -- not use email, save the
errors to a log, automatically log error reports in bug tracking
software, or whatever. There's also no limit imposed on the number of
error messages sent in Error::sendBugReport(), which is a bit dangerous.
Sam Dutton
...............................................
QtMsgHandler msgHandler;
void myMsgHandler(QtMsgType type, const char *msg)
{
switch (type)
{
case QtDebugMsg:
msgHandler(type, msg);
return;
case QtWarningMsg:
Error::sendBugReport("QtWarningMsg: " +
QString(msg));
return;
case QtFatalMsg:
Error::sendBugReport("QtFatalMsg: " +
QString(msg));
return;
}
}
int main(int argc, char **argv)
{
msgHandler = qInstallMsgHandler(myMsgHandler);
.
.
.
}
................................................
void Error::sendBugReport(const QString &text)
{
#ifdef _DEBUG
Error::warning(text);
#else
const QStringList &recipients =
QStringList::split(QRegExp("[;,\\s]"), bugReportToAddress);
QStringList::const_iterator end(recipients.end());
for (QStringList::const_iterator
it(recipients.constBegin()); it != end; ++it)
new Smtp(makeFromAddress(), *it, "Bug report",
makeMessage(text));
#endif
}
SAM DUTTON
SENIOR SITE DEVELOPER
200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK
P Please consider the environment. Do you really need to print this email?
-----Original Message-----
From: Lingfa Yang [mailto:lingfa@xxxxxxx]
Sent: Tuesday 02 October 2007 14:05
To: qt-interest@xxxxxxxxxxxxx
Cc: justin@xxxxxxx
Subject: Re: Who is the sender of a static signal?
Justin Noel wrote:
>
> You can catch all the debugs in an easier way. And you won't have to
> refactor all your debug code.
>
> Install a function pointer to catch all the qDebug() messages with
> qInstallMsgHandler().
>
> Then you can do whatever you want with the messages. You can even be
> creative and choose to output to a file in release and output to a
> QTextEdit window at runtime.
Justin,
I do not even know there is such a nice function, which is exactly what
I want.
Thank you very much for your helpful reply.
Regards,
Lingfa
--
[ signature omitted ]
Message 9 in thread
Dutton, Sam wrote:
>For what it's worth, we catch all errors reported by Qt in
>qInstallMsgHandler and have them emailed to developers without notifying
>the user.
>
>This seems to work better than presenting users with scary messages.
>
>Code below.
>
>For a non-Qt error, the user is notified and given the option of
>reporting (by email) the error, along with environment data.
>
>Obviously you could do this differently -- not use email, save the
>errors to a log, automatically log error reports in bug tracking
>software, or whatever. There's also no limit imposed on the number of
>error messages sent in Error::sendBugReport(), which is a bit dangerous.
>
>Sam Dutton
>
>
Sam,
Great! I like the msg handler, also I like your idea, as a developer, to
collect critical messages/bugs to improve the development.
Regards,
Lingfa
--
[ signature omitted ]
Message 10 in thread
Just my 2 bits on the subject... :)
I really don't like the idea of sending email behind the customers
back...
I would much prefer, the email be created, and require the user to hit
send... This way they know ALL the information my app is sending back to
support.
Scott
> -----Original Message-----
> From: Dutton, Sam [mailto:Sam.Dutton@xxxxxxxxx]
> Sent: Tuesday, October 02, 2007 9:12 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: Who is the sender of a static signal?
>
> For what it's worth, we catch all errors reported by Qt in
> qInstallMsgHandler and have them emailed to developers without
notifying
> the user.
>
> This seems to work better than presenting users with scary messages.
>
> Code below.
>
> For a non-Qt error, the user is notified and given the option of
> reporting (by email) the error, along with environment data.
>
> Obviously you could do this differently -- not use email, save the
> errors to a log, automatically log error reports in bug tracking
> software, or whatever. There's also no limit imposed on the number of
> error messages sent in Error::sendBugReport(), which is a bit
dangerous.
>
> Sam Dutton
>
> ...............................................
>
> QtMsgHandler msgHandler;
> void myMsgHandler(QtMsgType type, const char *msg)
> {
> switch (type)
> {
> case QtDebugMsg:
> msgHandler(type, msg);
> return;
> case QtWarningMsg:
> Error::sendBugReport("QtWarningMsg: " +
> QString(msg));
> return;
> case QtFatalMsg:
> Error::sendBugReport("QtFatalMsg: " +
> QString(msg));
> return;
> }
> }
>
> int main(int argc, char **argv)
> {
>
> msgHandler = qInstallMsgHandler(myMsgHandler);
> .
> .
> .
> }
>
> ................................................
>
> void Error::sendBugReport(const QString &text)
> {
> #ifdef _DEBUG
> Error::warning(text);
> #else
> const QStringList &recipients =
> QStringList::split(QRegExp("[;,\\s]"), bugReportToAddress);
> QStringList::const_iterator end(recipients.end());
> for (QStringList::const_iterator
> it(recipients.constBegin()); it != end; ++it)
> new Smtp(makeFromAddress(), *it, "Bug report",
> makeMessage(text));
> #endif
> }
>
>
>
>
>
>
>
>
> SAM DUTTON
> SENIOR SITE DEVELOPER
>
> 200 GRAY'S INN ROAD
> LONDON
> WC1X 8XZ
> UNITED KINGDOM
> T +44 (0)20 7430 4496
> F
> E SAM.DUTTON@xxxxxxxxx
> WWW.ITN.CO.UK
>
> P Please consider the environment. Do you really need to print this
> email?
> -----Original Message-----
>
> From: Lingfa Yang [mailto:lingfa@xxxxxxx]
> Sent: Tuesday 02 October 2007 14:05
> To: qt-interest@xxxxxxxxxxxxx
> Cc: justin@xxxxxxx
> Subject: Re: Who is the sender of a static signal?
>
> Justin Noel wrote:
>
> >
> > You can catch all the debugs in an easier way. And you won't have to
> > refactor all your debug code.
> >
> > Install a function pointer to catch all the qDebug() messages with
> > qInstallMsgHandler().
> >
> > Then you can do whatever you want with the messages. You can even be
> > creative and choose to output to a file in release and output to a
> > QTextEdit window at runtime.
>
>
> Justin,
>
> I do not even know there is such a nice function, which is exactly
what
> I want.
> Thank you very much for your helpful reply.
>
> Regards,
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> Please Note:
>
>
>
> Any views or opinions are solely those of the author and do not
> necessarily represent
> those of Independent Television News Limited unless specifically
stated.
> This email and any files attached are confidential and intended solely
for
> the use of the individual
> or entity to which they are addressed.
> If you have received this email in error, please notify
> postmaster@xxxxxxxxx
>
> Please note that to ensure regulatory compliance and for the
protection of
> our clients and business,
> we may monitor and read messages sent to and from our systems.
>
> Thank You.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 11 in thread
>> I would much prefer, the email be created, and require the user to
hit send... <<
I agree completely, but... This is an internal application, and the Qt
error messages are only of interest to the developers -- and were
annoying our users!
'Normal' error messages (i.e. where something goes wrong in our own
software) are reported to the user.
The main thing is not to lose error messages, and to log environment
information.
Sam
-----Original Message-----
From: Scott Aron Bloom [mailto:scott@xxxxxxxxxxxx]
Sent: Tuesday 02 October 2007 17:49
To: qt-interest@xxxxxxxxxxxxx
Subject: RE: Who is the sender of a static signal?
Just my 2 bits on the subject... :)
I really don't like the idea of sending email behind the customers
back...
I would much prefer, the email be created, and require the user to hit
send... This way they know ALL the information my app is sending back to
support.
Scott
> -----Original Message-----
> From: Dutton, Sam [mailto:Sam.Dutton@xxxxxxxxx]
> Sent: Tuesday, October 02, 2007 9:12 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: Who is the sender of a static signal?
>
> For what it's worth, we catch all errors reported by Qt in
> qInstallMsgHandler and have them emailed to developers without
notifying
> the user.
>
> This seems to work better than presenting users with scary messages.
>
> Code below.
>
> For a non-Qt error, the user is notified and given the option of
> reporting (by email) the error, along with environment data.
>
> Obviously you could do this differently -- not use email, save the
> errors to a log, automatically log error reports in bug tracking
> software, or whatever. There's also no limit imposed on the number of
> error messages sent in Error::sendBugReport(), which is a bit
dangerous.
>
> Sam Dutton
>
> ...............................................
>
> QtMsgHandler msgHandler;
> void myMsgHandler(QtMsgType type, const char *msg) {
> switch (type)
> {
> case QtDebugMsg:
> msgHandler(type, msg);
> return;
> case QtWarningMsg:
> Error::sendBugReport("QtWarningMsg: " +
QString(msg));
> return;
> case QtFatalMsg:
> Error::sendBugReport("QtFatalMsg: " +
QString(msg));
> return;
> }
> }
>
> int main(int argc, char **argv)
> {
>
> msgHandler = qInstallMsgHandler(myMsgHandler); .
> .
> .
> }
>
> ................................................
>
> void Error::sendBugReport(const QString &text) {
> #ifdef _DEBUG
> Error::warning(text);
> #else
> const QStringList &recipients =
> QStringList::split(QRegExp("[;,\\s]"), bugReportToAddress);
> QStringList::const_iterator end(recipients.end());
> for (QStringList::const_iterator
> it(recipients.constBegin()); it != end; ++it)
> new Smtp(makeFromAddress(), *it, "Bug report",
makeMessage(text));
> #endif
> }
>
>
>
>
>
>
>
>
> SAM DUTTON
> SENIOR SITE DEVELOPER
>
> 200 GRAY'S INN ROAD
> LONDON
> WC1X 8XZ
> UNITED KINGDOM
> T +44 (0)20 7430 4496
> F
> E SAM.DUTTON@xxxxxxxxx
> WWW.ITN.CO.UK
>
> P Please consider the environment. Do you really need to print this
> email?
> -----Original Message-----
>
> From: Lingfa Yang [mailto:lingfa@xxxxxxx]
> Sent: Tuesday 02 October 2007 14:05
> To: qt-interest@xxxxxxxxxxxxx
> Cc: justin@xxxxxxx
> Subject: Re: Who is the sender of a static signal?
>
> Justin Noel wrote:
>
> >
> > You can catch all the debugs in an easier way. And you won't have to
> > refactor all your debug code.
> >
> > Install a function pointer to catch all the qDebug() messages with
> > qInstallMsgHandler().
> >
> > Then you can do whatever you want with the messages. You can even be
> > creative and choose to output to a file in release and output to a
> > QTextEdit window at runtime.
>
>
> Justin,
>
> I do not even know there is such a nice function, which is exactly
what
> I want.
> Thank you very much for your helpful reply.
>
> Regards,
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> Please Note:
>
>
>
> Any views or opinions are solely those of the author and do not
> necessarily represent those of Independent Television News Limited
> unless specifically
stated.
> This email and any files attached are confidential and intended solely
for
> the use of the individual
> or entity to which they are addressed.
> If you have received this email in error, please notify
> postmaster@xxxxxxxxx
>
> Please note that to ensure regulatory compliance and for the
protection of
> our clients and business,
> we may monitor and read messages sent to and from our systems.
>
> Thank You.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]