| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 4 | |
Hello,
In the exec function of one dialog, I have the following :
[...]
QString noBug=noteEdit->toPlainText(); // get the textEdit content
qWarning("going to crash...");
qWarning(noBug.toAscii());
OTUtils::cleanString(noBug); // clean the string for an SQL statement
sql+="notes='"+noBug+"'";
[...]
As a test, I tried to paste a quite complicated string from a news paper on
the web
<http://www.lemonde.fr/economie/article/2008/08/27/edf-devrait-augmenter-ses-tarifs-pour-renover-son-reseau_1088279_3234.html>
and then it crashed at the qWarning(noBug.toAscii()); but only If I paste
the full text (Smaller part are OK).
The backtrace gives :
#5 0x080a1a91 in OTNewEventDlg::execAndProceed (this=0xbfa675f4) at
otneweventdlg.cpp:224
#4 0xb74cadc8 in qWarning () from /usr/lib/libQtCore.so.4
#3 0xb7517592 in qvsnprintf () from /usr/lib/libQtCore.so.4
#2 0xb7268c04 in vsnprintf () from /lib/tls/i686/cmov/libc.so.6
#1 0xb724788c in vfprintf () from /lib/tls/i686/cmov/libc.so.6
#0 0xb7278283 in strlen () from /lib/tls/i686/cmov/libc.so.6
Now, and this is what surprises me the most, to investigate the problem, I
created a slot to my dialog connected to the textChanged signal of the line
edit
void OTNewEventDlg::testReact(){
QString s= noteEdit->toPlainText();
qWarning(s.toAscii());
}
but here,when I paste the text inside it doesn't crash ! Moreover, and in a
way this is what is important to me, if I remove all the qWarning in that
part of my code, everything is Ok, the sql statement constructed with the
dialog is executed without any glitche.
Is it that I am making a mistake so obvious that I can't see it or there a
strange bug here ?
Regards,
Alain
--
[ signature omitted ]
On Quarta 27 Agosto 2008 14:39:30 denebet wrote: > qWarning(noBug.toAscii()); Are you sure that that string does not contain any printf-style replacements, like %s ? -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Thiago Macieira wrote: > On Quarta 27 Agosto 2008 14:39:30 denebet wrote: >> qWarning(noBug.toAscii()); > > Are you sure that that string does not contain any printf-style > replacements, like %s ? As I wrote, I took the string in a newspaper article, it does have some "%" inside and maybe after being pasted it becomes a printf-style replacement. I don't mind very much if I can't use it on very complicated strings, but I 'd prefer it to be explicitly written in the doc (well ,that may be obvious for people used to printf but I am not). Alain -- [ signature omitted ]
On August 27, 2008 10:36:09 am denebet wrote:
> Thiago Macieira wrote:
> > On Quarta 27 Agosto 2008 14:39:30 denebet wrote:
> >> qWarning(noBug.toAscii());
> >
> > Are you sure that that string does not contain any printf-style
> > replacements, like %s ?
>
> As I wrote, I took the string in a newspaper article, it does have some "%"
> inside and maybe after being pasted it becomes a printf-style
> replacement.
> I don't mind very much if I can't use it on very complicated strings, but
> I 'd prefer it to be explicitly written in the doc (well ,that may be
> obvious for people used to printf but I am not).
>
> Alain
Do this instead:
qWarning("%s", qPrintable(noBug));
--
[ signature omitted ]
Pascal Patry wrote:
>> Alain
>
> Do this instead:
> qWarning("%s", qPrintable(noBug));
>
OK, thanks.
Alain
--
[ signature omitted ]
denebet wrote: >I don't mind very much if I can't use it on very complicated strings, > but I 'd prefer it to be explicitly written in the doc (well ,that may > be obvious for people used to printf but I am not). It is explicitly written in the documentation at http://doc.trolltech.com/4.4/qtglobal.html#qWarning Quoting from it: "This function takes a format string and a list of arguments, similar to the C printf() function." And it gives an example of formatting. The documentation does not describe what the formatting is because that's explained much better in the C library documentation and in any C book. -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Do you get a warning when you compile? In Qt4, qWarning() expects a
const char*, but QString.toAscii() returns a QByteArray.
Try this instead:
qWarning(noBug.toAscii().data());
In Qt3 you could simply use QString.ascii(), but Trolltech did away with
that in Qt4.
Jason
-----Original Message-----
From: denebet [mailto:denebet@xxxxxxxxxxxx]
Sent: Wednesday, August 27, 2008 5:40 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: Strange bug with qWarning or QString.toAscii()
Hello,
In the exec function of one dialog, I have the following :
[...]
QString noBug=noteEdit->toPlainText(); // get the textEdit content
qWarning("going to crash...");
qWarning(noBug.toAscii());
OTUtils::cleanString(noBug); // clean the string for an SQL statement
sql+="notes='"+noBug+"'";
[...]
As a test, I tried to paste a quite complicated string from a news paper
on
the web
<http://www.lemonde.fr/economie/article/2008/08/27/edf-devrait-augmenter
-ses-tarifs-pour-renover-son-reseau_1088279_3234.html>
and then it crashed at the qWarning(noBug.toAscii()); but only If I
paste
the full text (Smaller part are OK).
The backtrace gives :
#5 0x080a1a91 in OTNewEventDlg::execAndProceed (this=0xbfa675f4) at
otneweventdlg.cpp:224
#4 0xb74cadc8 in qWarning () from /usr/lib/libQtCore.so.4
#3 0xb7517592 in qvsnprintf () from /usr/lib/libQtCore.so.4
#2 0xb7268c04 in vsnprintf () from /lib/tls/i686/cmov/libc.so.6
#1 0xb724788c in vfprintf () from /lib/tls/i686/cmov/libc.so.6
#0 0xb7278283 in strlen () from /lib/tls/i686/cmov/libc.so.6
Now, and this is what surprises me the most, to investigate the problem,
I
created a slot to my dialog connected to the textChanged signal of the
line
edit
void OTNewEventDlg::testReact(){
QString s= noteEdit->toPlainText();
qWarning(s.toAscii());
}
but here,when I paste the text inside it doesn't crash ! Moreover, and
in a
way this is what is important to me, if I remove all the qWarning in
that
part of my code, everything is Ok, the sql statement constructed with
the
dialog is executed without any glitche.
Is it that I am making a mistake so obvious that I can't see it or there
a
strange bug here ?
Regards,
Alain
--
[ signature omitted ]
Use qPrintable:
qWarning("%s",qPrintable(noBug));
http://doc.trolltech.com/4.4/qtglobal.html#qPrintable
On Wed, Aug 27, 2008 at 8:37 PM, Jason Machacek <jmachacek@xxxxxxxxxxx> wrote:
> Do you get a warning when you compile? In Qt4, qWarning() expects a
> const char*, but QString.toAscii() returns a QByteArray.
>
> Try this instead:
> qWarning(noBug.toAscii().data());
>
> In Qt3 you could simply use QString.ascii(), but Trolltech did away with
> that in Qt4.
>
> Jason
>
>
>
> -----Original Message-----
> From: denebet [mailto:denebet@xxxxxxxxxxxx]
> Sent: Wednesday, August 27, 2008 5:40 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Strange bug with qWarning or QString.toAscii()
>
> Hello,
>
> In the exec function of one dialog, I have the following :
> [...]
> QString noBug=noteEdit->toPlainText(); // get the textEdit content
> qWarning("going to crash...");
> qWarning(noBug.toAscii());
> OTUtils::cleanString(noBug); // clean the string for an SQL statement
> sql+="notes='"+noBug+"'";
> [...]
>
> As a test, I tried to paste a quite complicated string from a news paper
> on
> the web
> <http://www.lemonde.fr/economie/article/2008/08/27/edf-devrait-augmenter
> -ses-tarifs-pour-renover-son-reseau_1088279_3234.html>
>
> and then it crashed at the qWarning(noBug.toAscii()); but only If I
> paste
> the full text (Smaller part are OK).
>
> The backtrace gives :
> #5 0x080a1a91 in OTNewEventDlg::execAndProceed (this=0xbfa675f4) at
> otneweventdlg.cpp:224
> #4 0xb74cadc8 in qWarning () from /usr/lib/libQtCore.so.4
> #3 0xb7517592 in qvsnprintf () from /usr/lib/libQtCore.so.4
> #2 0xb7268c04 in vsnprintf () from /lib/tls/i686/cmov/libc.so.6
> #1 0xb724788c in vfprintf () from /lib/tls/i686/cmov/libc.so.6
> #0 0xb7278283 in strlen () from /lib/tls/i686/cmov/libc.so.6
>
> Now, and this is what surprises me the most, to investigate the problem,
> I
> created a slot to my dialog connected to the textChanged signal of the
> line
> edit
>
> void OTNewEventDlg::testReact(){
> QString s= noteEdit->toPlainText();
> qWarning(s.toAscii());
> }
>
> but here,when I paste the text inside it doesn't crash ! Moreover, and
> in a
> way this is what is important to me, if I remove all the qWarning in
> that
> part of my code, everything is Ok, the sql statement constructed with
> the
> dialog is executed without any glitche.
>
> Is it that I am making a mistake so obvious that I can't see it or there
> a
> strange bug here ?
>
> Regards,
>
> Alain
>
> --
> 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/
>
>
> --
> 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 ]