These commands should result in a plot being displayed in a Qt terminal window, followed by the window closing:
gnuplot> set term qt
gnuplot> plot(sin(x))
gnuplot> set term qt 0 close
The plot is created correctly but the window doesn't close. No error message is produced by gnuplot. Using 'wxt' instead of 'qt' results in the window closing as expected.
I have tried this in Gnuplot 4.6.6 running on Ubuntu 15.10, as well as Gnuplot 5.0.2 running on Arch Linux.
I suspect this is related to bug #1727. In both cases the issue is whether an event that is is pending when a a new terminal window is defined affects the old window or the new window. Remember that the "normal" way to close a window is using the mouse. You can generate a pseudo mouse event from the command line in some cases; i.e. "set term ... close" creates a close event just as clicking on the ⓧ icon in a window's title bar creates a close event and on some systems hitting alt-F4 while the mouse is over a window creates a close event. But the latter two events are unambiguously associated with a particular window, whereas something like a "refresh" or "resize" event could arguably be intended for either the previous or the next window.
Anyhow, I agree that "close" should be sent to the current window (because you can't close a window that hasn't been opened yet). My point is just that the same confusion as in bug #1727 is probably also responsible for the defered close handling.
Hi. I'm the original submitter. Thank you for the response. I don't know enough about gnuplot but your analysis sounds sensible.
However, it seems to me that, since the window number is specified in the "close" command, there is no ambiguity in this case, and the corresponding window should always be closed. The way I see it, the close command shouldn't necessarily be sent to the current window, but to the window specified in the command. By the way, this is the way that wxt and x11 terminals work, as far as I can see. This defect seems to be particular to qt terminals (or maybe qt just makes it easier to expose the problem).
I'm the maintainer of Gaston(https://github.com/mbaz/Gaston.jl), a plotting package for the Julia language that uses gnuplot as a backend. I need to be able to close windows reliably from the command line. As one example, imagine running unit tests and leaving the user's workspace filled with plotting windows that need to be closed one by one. For the time being, I'm just going to disable qt terminals.
On windows situation is slightly different.
On Ubuntu for both gnuplot-5.0.3 and 5.1.0 (ChangeLog 2016-03-13), qt plot window does not close.
However on windows for gnuplot-5.0.3, qt plot window does not close but for 5.1.0 (ChangeLog 2016-03-10) qt plot window closes.
You can try the attached patch against 5.0.3 (applies also to current CVS).
As tested on linux, "set term qt N close" closes window N immediately but leaves the current window active.
This sequence now works:
However, if you close the current window then you will get an error message if you try to plot into it after closing. This is not good, so I have not applied this patch yet in cvs.
Please let me know whether the behavior is the same on Windows.
I have not tested on windows yet but reports results on Ubuntu 14.04.
I have attached the patch to 5.0.3 source and tries the sequence that you have shown the above.
It works ad expected.
As you said, the following gives an error:
Last edit: Tatsuro MATSUOKA 2016-03-15
Results on windows for 5.0.3,
The patch makes qt plot window close.
Behaviors resemble thoes happen on Ubuntu.
The first example wokrs as expected.
The second one;
Last edit: Tatsuro MATSUOKA 2016-03-15
The second report for windows: (Results for 5.1.0 (ChangeLog 2016-03-13) without patch )
Results are just the same as those on 5.0.3.
It seems the "window not responding" behaviour can be avoided by this change:
QtGnuplotWindow.cpp:60
// What is the benefit of setting this?
// setAttribute(Qt::WA_DeleteOnClose);
I do not know if removing this line causes any unwanted side effects.
So far I have not seen any bad results, so let's try it out.
Does it prevent the hang you report for 5.0.3 on WIndows?
If we are lucky, this might also fix Bug #1554
Ethan
I tried your change on 5.0.3 source on windows.
Comment out line 60 in QtGnuplotWindow.cpp makes "hang" problem corrected.
In addtion the change also fixes Bug #1554 also on windows.
Great!
I will mark both bugs "fixed".
In the current cvs, the problem is fixed on windows. Thanks!