ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  QT Multiwindow support
Posted by Dave on Jun-02-2020 03:01
In my scenario, under QT 5.13, I have a main window with some user interaction and display elements and buttons, where one of the buttons displays the chat, in this case, I am using the sample class in TrackFinance (deleting the "main" piece of code in the file file).

I need both windows to be able to display and interact with the user.

The code in the mainwindow button to display the chart is:

    TrackFinance Chart1;
    Chart1.setModal(true);
    Chart1.exec();

With this code the chart displays BUT BLOCKS the mainwindow until the chart is closed.

The preferred way to issue a non blocking widget display would be with

    Chart1.show();

BUT this does not show anything when called from another window, although it works with the original main program from the demo...

Thanks for the help!

David

  Re: QT Multiwindow support
Posted by Dave on Jun-02-2020 03:09
Above where it says display the chat, please read display the chart...

  Re: QT Multiwindow support
Posted by Peter Kwan on Jun-02-2020 12:44
Hi Dave,

How the TrackFinance object is created? Is it declared on stack as a local variable, like:

TrackFinance Chart1;
Chart1.show();

The above code creates a TrackFinance object, then it displays the TrackFinance dialog, and it probably destroys the TrackFinance immediately. So it is expected nothing is displayed or the dialog just pop up for a second and disappear. The same will occur to any type of window, not just TrackFinance.

The TrackFinance is destroyed because Chart1 is local variable. If the code continues to run after the dialog is opened, the Chart1 will soon go out of scope. It will then be destroyed and its destructor will be called.

The above does not occur if it is a modal dialog because the code cannot continue before the dialog is closed, so the Chart1 cannot go out of scope.

If you want to use a non-modal dialog, please put Chart1 in some location that will not be destroyed. Either allocate it on the heap or put is somewhere that it will not go out of scope (like as a member variable of your main window class, which will not be destroyed unless your main window is destroyed).

Regards
Peter Kwan

  Re: QT Multiwindow support
Posted by Dave on Jun-03-2020 22:42
Thaks!

I got it working!!

  Re: QT Multiwindow support
Posted by Dave on Jun-04-2020 00:27
So, I got it working with the vanilla example, BUT I need to make my data available to the chart, which I'm doing by passing my data management class to the Chart.

So, in the Start button I have

    SixSVChart VChart1m("ES", 1);  // This is my data management class
    Chart1 = new TrackFinance (VChart1m);  // I modified the class to take my class as
                                                   // argument but no other changes to your original class
    Chart1->show();

This gives me a black screen....

The intent is to add the following right after that piece of code:

    While there is more data
        Read and process the data for my indicators (in VChart1m)
        Chart1->UpdateChart ; // Need to develop this...

Only Change to the constructor :

TrackFinance::TrackFinance(SixSVChart SixS, QWidget *parent) :
    SixSData (SixS)
    ,QDialog(parent)


Thanks for the help

  Re: QT Multiwindow support
Posted by Dave on Jun-04-2020 04:16
Update...

I Moved the following to the constructor of the Main Window:

    SixSVChart VChart1m("ES", 1);  // This is my data management class
    Chart1 = new TrackFinance (VChart1m);  // I modified the class to take my class as
                                                   // argument but no other changes to your original class


And the button to start has:

    Chart1->show();
    if (testData->start()) {} // This loads the first 130 bars and computes my technical stuff

And that displays the original chart in your example.

Now I updated the start button to have:

    Chart1->show();
    if (testData->start()) {
        while (testData->next()){  // This loads the next bar and computes technical stuff
            //Chart1->redraw();  // Not implemented yet
        }

Now the chart screen is black. It seems to me its running nonblocking but doesn't get to complete...

Surely I am missing something

Many thanks!

Dave

  Re: QT Multiwindow support
Posted by Peter Kwan on Jun-04-2020 12:04
Hi Dave,

Are you familiar how GUI works?

I am not sure in detail how the Qt GUI works, but it is normal to expect right after "Chart1->show();", nothing will happen in the GUI. It is because you are using the GUI thread to run "Chart1->show();", so Qt cannot update the GUI because as it cannot use the GUI thread while your code is in the GUI thread. But sooner or later your code must end. For example, if the chart is displayed when the user press a button, then your code is probably running in the click event handler. After handling the event, your code must leave the event handler at some point. At that time the Qt can run in the GUI thread to update the GUI.

For your case, if "if (testData->start()) {}" works, but  "if (testData->start()) {         while (testData->next()){}}" does not work, there are two possibilities:

(a) Your while loop is an infinite loop, and it never ends. So your code never leaves the event handler. So Qt cannot update the GUI.

(b) All the data are consumed in the while loop until there is no data left. Your code can then leave the event handler and Qt can update the GUI, but there is already no data left for the chart.


For the same reason, the following code, if running in a GUI thread, cannot possibly work as you expect. The code keeps updating the chart, but does not allow anything to display (as it does not leave the GUI thread).

while (testData->next()){}
   Chart1->redraw()
}


For your reference, you can refer to our real time chart sample code. After we draw the chart, we always leave the event handler to allow Qt to update the GUI. The chart is never drawn more than once in any event handler (and certainly not in a loop).

Regards
Peter Kwan

  Re: QT Multiwindow support
Posted by Dave on Jun-04-2020 17:54
Hi Peter!

First, Thank you with your patience!

While my grasp of C++ is from a while back (quite awhile - after retirement I am developing this very ambitious project). Your explanation is very clear and sent me on a learning loop on GUI event loops and threads...

Got it working now with your random data generator. Working on replacing with my data retrieval layer. Learning about DoubleArrays... :)

Dave