Qt layer and QApplication

Hi all,

I have a question, before I spend more time digging into it.

When I saw there is a Qt layer and that you can embed TCanvas in QWidgets I thought: “Great!!!”

The thing didn’t last too long, because when I looked into the example, it seems you have to run TRint instead of the Qapplication. That is not to nice, since I have my Qt program and I want to include TCanvases with the minimum possible impact. I still want my main to call QApplication. Now the question is if I can include canvases like that.

If it isn’t posible please let me know so I don’t spend much time trying in vain.

If you have hints please let me know as well.

Hi
check www-linux.gsi.de/~go4/qtroot/html/qtroot.html

Regards. Valeriy

Thanks Valeri for your reply.

I tried that and it worked. Now a question out of curiosity:

Isn’t it possible to do it without having to create the TQApplication? I mean using QApplication… does it have to do with the fact that Root runs the Qapp in a thread other than the main thread? because one would naively think that the canvas class that inherits from QWidget shouldn’t have to know anything about the innerworkings and all the communication with the gui thread is implemented somewhere else.

Later, if the histograms use this class instead of the standard canvas class they don’t know what goes behind the scenes. That allows gui changes and all in a transparent way (isn’t it one of the nice thigs of C++?).

again, thanks for your reply.

Javier

With Qt layer it is possible to mix any Qt and Root widgets

See:
root.bnl.gov

root.bnl.gov/QtRoot/QtRoot.html#embed

You can find an example of the “normal” working Qt project there

root.bnl.gov/QtRoot/QtRoot.html#designer

You still have a question just drop me a message
to clarify your needs and Qt layer capabilites.

[quote=“javierggt”]Hi all,

I have a question, before I spend more time digging into it.

When I saw there is a Qt layer and that you can embed TCanvas in QWidgets I thought: “Great!!!”

The thing didn’t last too long, because
when I looked into the > example, it seems you have to run TRint > instead of the Qapplication.

The answer is "Yes and “No”.

No, you can create QApplication on your own. Even more you can KApplication if you are goinmh to use KDE Widgets.

Yes, However to use ROOT you still need to create TRint.

I hope it is clear. What really happens TRint just saves you some time by creating QApplication internally.

That is not to nice, since I have my Qt program and I want to
include TCanvases with the minimum possible impact. I still want
my main to call QApplication.
Now the question is if I can include canvases like that.

No problem with your main, but to use TCanvas you have to have TRint as well. You have to create it at some point.

If it isn’t posible please let me know
so I don’t spend much time trying in vain.

It is possible,

If you have hints please let me know as well.[/quote]

[quote=“fine”][quote=“javierggt”]

Hello
I’ve realized I was not correct answering your question.

The right answer of your question,

"Now the question is if I can include canvases like that. "

is

    Yes, you can period.

I made one line correction of my code (thanks this discussion to bring things up)

You can pick the last version of Qt layer
root.bnl.gov/QtRoot/QtRoot.html#source
This correction will be included into the ROOT CVS also.
However the BNL CVS allows you to update the Qt layer of your ROOT production version (which is 4.00.08a at the moment)
(see: root.bnl.gov/QtRoot/QtRoot.html#install )

aYou can pick the Qt project, where the “main” is the that created automatically by Qt designer and it contains NO ROOT dependency.
(see: root.bnl.gov/QtRoot/QtRoot.html#designer) to pick the project)

I got the thing working with Qt Designer and everything

I just wrote my own little class to modify the way the canvas is created and it is fine.

I’m actually trying to run QApp in a separate thread, so it’s funny you mention it Valeriy. The only problem seems to be when there is a QEvent so I was thinking of doing some sort of “registration” of the classes and making the QApp instanciate the widgets (like a manager).

that’s it… matter closed :slight_smile:

[quote=“javierggt”]I got the thing working with Qt Designer and everything

I just wrote my own little class to modify the way the canvas is created and it is fine.
[/quote]

I think with the current version of TQtWidget one would not need to modify the TCanvas. (thanks this discussion. Such essential functionality was missed indead)

Just a comment about Qt thread. The Windows version does use the separate Qt Gui thread and it does send messages from one thread to another one. My feeling one will need it to run Qt layer with the “native” Mac interface also.

For further infromation just look up the code from your $ROOTSYS/qt directory.

[quote=“javierggt”]
that’s it… matter closed :slight_smile:[/quote]

Agree :slight_smile: Let’s move on ](*,)

[quote=“Valeriy Onuchin”]Hi,
I mentioned thread-safety just simply after
reading doc.trolltech.com/3.3/threads.html

Regards. Valeriy[/quote]

Valerie, please read the up-to-date information

doc.trolltech.com/4.0/threads.html

Thanks. I appologize. I’m silent.
No more Qt/QtRoot related messages

Regards. Valeriy