Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, April 2007
Show java tracktrace with native warnings


Message 1 in thread

Hi,

Sometime we develop things wrong and get warnings from Jambi like
"QGraphicsScene::addItem: item has already been added to this scene" or
"QWidget::setLayout: Attempting to add QLayout "" to QDialog "", which
already has a layout".

I guess this output is produced in C++, but is it possible to provide a
java stacktrace to where this happened ?

-=Børge


Message 2 in thread

Børge Austvold wrote:
> Hi,
> 
> Sometime we develop things wrong and get warnings from Jambi like
> "QGraphicsScene::addItem: item has already been added to this scene" or
> "QWidget::setLayout: Attempting to add QLayout "" to QDialog "", which
> already has a layout".
> 
> I guess this output is produced in C++, but is it possible to provide a
> java stacktrace to where this happened ?

Hi Børge,

Right now this is not possible. These messages are typically produced by 
calls to qWarning() in the C++ code when some piece of the code is used 
in a bad, but not fatal, manner.

In Qt/C++ you can intercept these messages using qInstallMsgHandler() 
that takes a pointer to a function. You then decide how to display the 
message. I'm thinking it may be possible to install our own message 
handler for Qt Jambi, and provide you with an interface and a function 
along the lines of:

public interface QMessageHandler {
     enum Type { Debug, Warning, Error, System }
     public handleMessage(Type type, String message);
}

and a function

QCoreApplciation.installMessageHandler(new QMessageHandler() {
    ...
});

I'm just thinking out loud, but from the message handler you could print 
the current stack trace so I think that would give you what you want...

So, to be clear..., I'm not saying we'll add this but I like the idea of 
being able to intercept warnings sent to the shell so I'll look into it 
and see if and where it can be put.

You can of course try to add similar functionality using the Qt Jambi 
Generator.

best regards,
Gunnar


Message 3 in thread

Hi Gunnar,

I guess that if you add support for a message handler I could always do
a new Throwable().printStackTrace() in the handleMessage, but I'm not
sure if this stack would include the original java steps that where
executed before the JNI code that created the warning. If they do it
would be great as I can produce the stacktrace manually while debugging :)

-=Børge


Gunnar Sletta wrote:
> Børge Austvold wrote:
>> Hi,
>>
>> Sometime we develop things wrong and get warnings from Jambi like
>> "QGraphicsScene::addItem: item has already been added to this scene" or
>> "QWidget::setLayout: Attempting to add QLayout "" to QDialog "", which
>> already has a layout".
>>
>> I guess this output is produced in C++, but is it possible to provide a
>> java stacktrace to where this happened ?
> 
> Hi Børge,
> 
> Right now this is not possible. These messages are typically produced by
> calls to qWarning() in the C++ code when some piece of the code is used
> in a bad, but not fatal, manner.
> 
> In Qt/C++ you can intercept these messages using qInstallMsgHandler()
> that takes a pointer to a function. You then decide how to display the
> message. I'm thinking it may be possible to install our own message
> handler for Qt Jambi, and provide you with an interface and a function
> along the lines of:
> 
> public interface QMessageHandler {
>     enum Type { Debug, Warning, Error, System }
>     public handleMessage(Type type, String message);
> }
> 
> and a function
> 
> QCoreApplciation.installMessageHandler(new QMessageHandler() {
>    ...
> });
> 
> I'm just thinking out loud, but from the message handler you could print
> the current stack trace so I think that would give you what you want...
> 
> So, to be clear..., I'm not saying we'll add this but I like the idea of
> being able to intercept warnings sent to the shell so I'll look into it
> and see if and where it can be put.
> 
> You can of course try to add similar functionality using the Qt Jambi
> Generator.
> 
> best regards,
> Gunnar


Message 4 in thread

Børge Austvold wrote:
> Hi Gunnar,
> 
> I guess that if you add support for a message handler I could always do
> a new Throwable().printStackTrace() in the handleMessage

Or better yet:
Thread.dumpStack();

> , but I'm not
> sure if this stack would include the original java steps that where
> executed before the JNI code that created the warning. If they do it
> would be great as I can produce the stacktrace manually while debugging :)

They would... Just try it in any virtual Jambi function that is called 
from C++. It will print you the entire stack trace starting in 
QApplication.exec() into your addItem() and then into the current one.

-
Gunnar


Message 5 in thread

Hi,

I guess that this will be included in next beta then ? :)

-=Børge

Gunnar Sletta wrote:
> Børge Austvold wrote:
>> Hi Gunnar,
>>
>> I guess that if you add support for a message handler I could always do
>> a new Throwable().printStackTrace() in the handleMessage
> 
> Or better yet:
> Thread.dumpStack();
> 
>> , but I'm not
>> sure if this stack would include the original java steps that where
>> executed before the JNI code that created the warning. If they do it
>> would be great as I can produce the stacktrace manually while
>> debugging :)
> 
> They would... Just try it in any virtual Jambi function that is called
> from C++. It will print you the entire stack trace starting in
> QApplication.exec() into your addItem() and then into the current one.
> 
> -
> Gunnar


Message 6 in thread

Børge Austvold wrote:
> Hi,
> 
> I guess that this will be included in next beta then ? :)

As I said initially, I'll investigate it. It will not be part of the 
upcoming beta.