How can I pass data bidirectionally between two classes in C++ - c++

I am working with the MVC architecture. I have my GUI all set up, and I have my controller using the model for data access. My question is: how do I set up bidirectional data flow between the controller and the GUI(view). I am using Qt, so When I hit a button, it will fire off an action. In order to make that Action fire off to the controller, I need an instance of it. Then from the controller side, I need an instance of the view so I can tell it how to behave. So, how can achieve this communication? Am I even on the right track? please let me know what you guys think.
Thanks

The view doesn't need to be explicitly aware of the controller. The controller can connect to any of the view's signals and the signals can relay relevant data or they can be empty. When the controller handles them in a slot, it can call methods on the view to fetch data if it isn't already included in the signal. The controller can also call any view method at any time.
I usually connect widget(button) signals directly to slots in the view class and expose custom aggregate signals that a controller can connect to instead of exposing all the widgets themselves.

Related

Item updated via CSOM will not fire remote event receiver

We have a remote event receiver associated to a list and hooked on all events there. When you update any list item using OOB SharePoint page, the event receiver is executed; a web service which is taking care of the afterward actions works nicely. However when you update item use CSOM code e.g. in simple console application, nothing happens. The event receiver is not called at all. I found this issue on both SP 2013 and 2016.
I will not post any code while it is irrelevant: item is updated using standard approach and values are actually changed in the list item, only the event receiver is not fired. To put it simply:
item updated manually from site -> event receiver fired
item updated via CSOM -> event receiver not fired.
I remember similar issue on SharePoint 2010 when using server side code and system account. Could it be that behind the scene web service called by CSOM (e.g. list.asmx) is using system account to make changes as well? It's just hypothesis...
So after deeper investigation and many try/fails we found out it was indeed issue with code in our event receiver. For some strange reason original developers were checking Title field in after properties and cancelling code if not present. I guess it was probably an attempt to prevent looping calls.
One lesson learned: When using CSOM after event properties contains only those fields which were altered by CSOM code. Keep it in a mind in case you need to use other values than those you want to update. You may need to stupidly copy and assign them again just because of this.

Block GUI when waiting for QTcpSocket data

I am writing a program to interact with a network-based API using Qt.
The interaction with the API is made with XML messages (both queries and results)
I implemented the communication and data processing in a class in a shared library project and I have a QMainWindow in which the user can enter the connection details. When clicking on the connect button, the following should happen:
1. An instance of the connecting class is created.
2. A connection message is sent to the API to get the session ID. The answer is parsed and a session ID is stored in the class instance.
3. A message is sent to the API the get some field information. The XML is then parsed to extract the required field information to get data from the API.
4. Another message is sent to get the data matching the fields. The XML answer is then parsed and stored in a data structure for processing.
5. The data is then processed and finally displayed to the user.
I made a simple console program to test the library and it is working fine - no message is sent before all the data from the previous message has been processed. However, when I implement the same process in a QMainWindow instance, no wait occurs and messages are sent one after another without waiting.
How can I block the GUI thread to wait for full processing before sending the next message?
Thanks
Blocking the UI isn't achieved by blocking the event loop. It's done by disabling the widgets that you don't want to allow interaction with - either by literally calling disable() method on them, or by guarding the interaction based on some state variable, e.g.:
connect(button, &QPushButton::clicked, button, [this]{
if (! hasAllData) return;
// react to a button press
});
All you need is to define a set of states your application can be in, and disable relevant widgets in appropriate states. I presume that once the session is established, it'd be fastest to issue all queries in parallel anyway, and asynchronously update the UI as the replies come back in real time.

Call an action only once when it's called from two places

I have an app we have connected to Pubnub for a live socket service to keep data on the page fresh for the user.
I have an ajax call that will do something with our API, and when it is successful I call an action on the application controller. At or around the same time, as long as Pubnub is still connected it receives a message with the action handler name and it attempts to call the same action.
Ideally I want to make sure this code only runs once weather it was first called by Pubnub or by my ajax success callback. How can I do this maybe using the ember run loop? It seems viable here I'm just not able to wrap my head around how I would actually do this.
Well, I would only use the web socket.
But for your question:
There is not build-in functionality in the runloop to do that. You will need some kind of uniq message id, and then have a list of processed messages and check there before you run your code.

Fire action in Backbone View after two events have been triggered

I understand how to bind an action in a Backbone View to an event trigger but, how can you fire an action watching the condition that two precise envets have been triggered?
For that you can use jquery functionality like:
$.when(func1, func2).then(func3);
It acts like deffered and promise here.

Is it possible to get access to the HTTP Context from within a Sitecore Event handler?

I am building a custom event handler for the Sitecore security:loggedin event. Basically I want to run some code every time a user logs in. Is it possible for me to get access to the HttpContext (application level variables, etc) from within the event handler code? From what I can tell the only argument that is passed in is the User object for the user that just logged in.
Thanks,
Corey
Yes, this is entirely possible:
if (System.Web.HttpContext.Current != null)
{
//do what you like
}