Hi Tony,
try:
rc->Connect("CloseWindow()", "DvatCanvas", this, "monitorClose()");
this way you tell the system to use the DvatCanvas::monitorClose() slot
for "this" instance of DvatCanvas.
Cheers, Fons.
On Wed, 2002-02-20 at 17:13, Colley, Tony wrote:
> I have a stand-alone application linked with the ROOT libraries. I create a
> canvas and draw a histogram or graph on it. I want to know when the user
> closes the canvas so that I can clean up (and not try to delete the canvas
> later, which causes ROOT to "**break** segmentation violation").
>
> So I searched the ROOT web site. I read the article on "How to Use the
> Signal/Slot Communication Mechanism"... I read the email thread with the
> subject "attaching action to window close". I tried the solution proposed by
> Fons in his 30 Oct 2000 email in that thread. And I get the error indicated
> in the above subject line when I call Connect.
>
> I searched the ROOT web site more. I found several emails over the last few
> years asking similar questions, but the thread I just mentioned is the only
> time anyone responded publicly.
>
> So now I ask for help.
>
> Excerpts of code:
>
> -- From DvatCanvas.h file -----
>
> #include "TCanvas.h"
> #include "RQ_OBJECT.h"
>
> class DvatCanvas
> {
> RQ_OBJECT("DvatCanvas");
>
> public:
> [edited]
>
> // FUNCTION TO MONITOR CLOSING OF CANVAS
> void monitorClose();
>
> [edited]
> private:
> TCanvas *m_canvas;
>
> [edited]
> };
>
>
> -- From DvatCanvas.cpp file -----
>
> static long canvas_number = 0;
>
> // PRIVATE FUNCTION TO CREATE CANVAS
> void DvatCanvas::createCanvas( int width, int height, int xpos, int ypos )
> {
> ostringstream cname;
>
> ++canvas_number;
> cname << "canvas" << canvas_number;
>
> m_canvas = dcs_create_canvas( cname.str(), width, height, xpos, ypos );
>
> TRootCanvas *rc = (TRootCanvas*)m_canvas->GetCanvasImp();
> rc->Connect("CloseWindow()", 0, 0, "monitorClose()");
>
> return;
> }
>
> // FUNCTION TO MONITOR CLOSING OF CANVAS
> void DvatCanvas::monitorClose()
> {
> cout << "DvatCanvas::monitorClose" << endl;
> }
>
> -------- END OF CODE EXCERPTS --------------
>
> Note that the function dcs_create_canvas requests the "GUI Thread" to create
> a TCanvas and return it to the "current thread". As I explained in an
> earlier email thread, this is how I got the ROOT libraries to work in a
> multi-threaded application.
>
> Also note that the DvatCanvas::createCanvas() function is called by all of
> DvatCanvas's constructors.
>
> Anyway, everything works fine... the canvas is created, stuff is drawn on
> it, the user can interact normally with the canvas and its objects... except
> when I call Connect() I get the message:
>
> Error in <TQObject::CheckConnectArgs> slot monitorClose does not exist
>
> And, of course, monitorClose() is not called when the user closes the
> canvas.
>
> I tried specifying "DvatCanvas::monitorClose()" in the Connect call, but
> that didn't make any difference.
>
> Help!
>
> Tony Colley
> ITT Industries A/CD
> Fort Wayne, IN USA
> Tony.Colley@itt.com
>
> ************************************
> If this email is not intended for you, or you are not responsible for the
> delivery of this message to the addressee, please note that this message may
> contain ITT Privileged/Proprietary Information. In such a case, you may not
> copy or deliver this message to anyone. You should destroy this message and
> kindly notify the sender by reply email. Information contained in this
> message that does not relate to the business of ITT is neither endorsed by
> nor attributable to ITT.
> ************************************
--
Org: CERN, European Laboratory for Particle Physics.
Mail: 1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248
WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET