Notified when file created or opened

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Notified when file created or opened

Post by Taygete » Fri Oct 17, 2014 2:08 pm

Hi Andrew,

Is there a listener which I can use (c++) which notifies me when a user creates a new drawing or opens an existing one?

I have hooked into RFocusListener but this seems to only get called if the user has more than one drawing open and they switch tabs (selecting one drawing then the other...).

Thanks,

Andrew.

Edit: Okay after some further testing it does seem to notify me when the user creates a new drawing or opens an existing drawing.

Where it is failing is when you launch QCad; I am not being notified the default drawing (the one which is auto created on launch) has been created. I am guessing this is because my C++ plugin which has the RFocusListner in has not been initialised?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Notified when file created or opened

Post by andrew » Sat Oct 18, 2014 11:21 am

Taygete wrote:Is there a listener which I can use (c++) which notifies me when a user creates a new drawing or opens an existing one?
Listeners for this have been added in the current development version of QCAD:
https://github.com/qcad/qcad/blob/maste ... Listener.h
https://github.com/qcad/qcad/blob/maste ... Listener.h
Where it is failing is when you launch QCad; I am not being notified the default drawing (the one which is auto created on launch) has been created. I am guessing this is because my C++ plugin which has the RFocusListner in has not been initialised?
Yes, this has also changed for this reason. Plugins are now being notified at various stages while QCAD is loading:

The postInit method of your plugins is now called four times in this order with a status argument:
- When the main window is available (no documents open yet)
- Files given on the command line have been loaded, respectively, a new empty document has been created
- Scripts passed on the command line have been executed
- All work has been done and QCAD is ready to receive user input

If you want to register a listener, best do it when postInit is called with status==RPluginInterface::GotMainWindow.

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: Notified when file created or opened

Post by Taygete » Sat Oct 18, 2014 11:54 am

Thanks Andrew, I will take a look over the weekend, I did find a workaround but will implement your method instead.

Andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”