Control c++ application remotely via web interface - c++

I created a C++ QT application on Linux with a simple visual interface with three buttons. This application runs on a machine with a certain IP address in my wifi network. I want to be able to access such visual interface from the browser of a smartphone and click the buttons.
To accomplish this I used a remote desktop connection, but it's just a temporary solution as I want to be able to access my GUI from any smartphone without the need of installing anything, and also without offering other functionalities... the client should be able to press the three buttons and nothing more.
In other words, I would like to be able to do the following:
After I type the IP address of the linux machine in the browser of my smartphone, a html page opens up with my visual interface with three buttons;
When I press one button, my C++ code starts running in the background;
When I press again the buttons, the C++ app receives the commands and acts accordingly.
And so on until I click the button that closes my C++ App.
Now, is there a way to accomplish this? In a few words, is it possible to have a web interface to act as a GUI for my C++ app? I must admit I am really ignorant in web applications :) But maybe you know about a QT widget that solves my problems.
Thanks!

There are a lot of ways to accomplish this.
A simple way is to use QtHttpServer to talk to the objects inside your Qt Application to do the work you asked it to.
You can quickly get started by adapting the example here to your use case.

You may want to check out https://sourceforge.net/projects/conair/ - this lib allows you to communicate with your c++ qt code via javascript. You would, however, have to replicate your existing qt gui with a traditional web front-end technology - some straight forward HTML and javascript would probably suffice.

Related

Qt c++ application scraping

I would like to interact with an opened qt window (wrote in c++) using code. The code would act like a user and will be completely independent of the code of the qt window. Something like web scraping but with qt (which is much more complicated).The first thing I’m attempting to do is to mimic a click on a push button.
My first intuition was to add some c++ code to the existing code at runtime and execute something like « pushButton.click(); ». After some few searches I tried to use dynamic shared library. The library would implement the code of the button I want to click on, and would be dynamically added to the existing c++ code. This solution could work but seems to be very complicate and not portable. Furthermore I would like the solution to be very independent of the window code.
Of course the qt code of the window will be accessible from the scraping code side.
Are some other solutions more practical ?
EDIT:
GammaRay seems to work fine. I manage to perform a click on a pushButton using the GUI. However, GammaRay doesn't seem to provide a command line interface form. As we can read in the official documentation:
The GammaRay client is available in two forms:
as a standalone application as depicted in the following screenshot
as Qt Creator plugin (for Qt Automotive Suite only)
Is there any possibility to perform a click using GammaRay and without GUI? Are some other solutions work using code only?
The purpose of GammaRay is introspection and not automation. I recommend to use Squish (https://www.froglogic.com/de/squish/editions/qt-gui-test-automation/), depending on the required licenses the price is not so high.
If you don't want to spent the money, then you have to create your own IPC Interface with Remote Commands.

Embedd an external application in a widget under Qt

I was wondering either it is possible to run an external application inside a QT widget under windows operating system. For example, if I were to write a Qt gui application, where in one of the dialogs user could write some text, I could use a textbox there or something similar. But instead, would it be possible to run Notepad++ or windows notepad application in that dialog?
I would appreciate all help.
It is not really practical to do what you describe at the application level, embedding an entire process into a window of another. (It would be technically difficult and the user experience would likely be pretty bad if you could pull it off.)
Fortunately, this very problem of application components has already been solved!
So it is possible to get the end result you describe via a slightly different mechanism. Many applications expose COM interfaces for automation and embedding, and it is possible to embed COM objects within a Qt application.
(Older technologies such as DDE, OLE and ActiveX provided various aspects of this but are all basically deprecated in favour of COM AFAIK.)
Hopefully you can find a COM object from a third party, or find an app that exposes its components via COM and assemble your app that way.
Have a look at the Qt documentation:
Active Qt - ActiveX and COM support for Qt

Make Non-GUI server application in Visual Studio

I did a project of Server Socket in Visual studio in C++ MFC based. Now, after debugging the project, server GUI opens, then after clicking on the CONNECT button on server GUI, you can connect the clients to that server and so on.
Now I want to use that server exe file in some other computer. So that whenever that computer starts, that server exe automatically starts. so for this i need to disable the connect button, so that after debugging, server GUi opens and connected automatically. But i don't want that server GUI opens in another computer in autostart as well. i want to disable that server GUI.
I got an idea of modalless dialog to work on it. Is it good or what approach should I use ?
You probably want to separate GUI part and server part of your application. Ideally, if your server is actually a server, you should start it as service. Then you will have separate GUI tool to control it.
Another approach is to have command line argument that determines whether server should be started with GUI enabled or disabled.
The only professional and stable solution of such an application is, to splitt it in a console part, which you put under the control of service control and a gui part wich the user can start when he wants.
I tried solutions like yours and so I can tell you from my own experience, that you will face a lot of problems.
However, a possible solution would be to hide the window and lay the app down to systray and this is a very interesting discussion about hinding windows.
Additionaly I have two good advices in case of MFC:
Never ever just "copy-past" code without to know what MFC is doing in the background (Win32api).
Do not use MFC. Have a closer look at QT or wxWidges when you need windows, to shortcut encapsulation of win32api also have a look at boost library. It is realy worth the time you spend on!
Good luck!

How to customize right click with already existing instance of a program?

I need to customize right click so that I can scan a directory with my anti-virus. I know how to do that using registry keys, but the problem is that I don't want to start a new instance of my program every time I want to scan a directory. My anti-virus needs to load some signature databases so it will take around 15 seconds for the program to load those. I need to use the instance of the program which I have already opened and is running for scanning the directory. How can I do that?
I am using C++Builder.
Thanks.
Considering you already know how to add the item to the right click contextual menu, I suggest implementing a client/server set of applications:
A server that loads up when you turn your computer on and does the scanning, and
The client that tells it what to do using IPC - inter-process communication.
You then add the client application to various contextual menus, passing it arguments that indicate what it should get the server to do depending on what you right-clicked on.
IPC is a bit of a pain in the butt, the easiest way is to use TCP/IP to and do local networking using a network library. There are many out there, however given you'll likely want to have other features such as UI elements and a tray icon, I suggest you look at Qt, namely the following components:
QtNetwork: For performing communication between the client and the server executable.
QSystemTrayIcon: For displaying a small icon on the tray.
There are quite a few other little bits of Qt you'll no doubt encounter (like all the fabulous UI stuff), and fortunately Qt is well documented and help is always available here, and from the Qt Developer Network. You can get started with Qt by downloading and installing the SDK:
http://qt.nokia.com/downloads/
Best of luck :).
Implement a DDE server in your anti-virus, and then add a ddeexec subkey to your Registry key. Alternatively, add an OLE Automation object to your app that implements the IDropTarget interface, and then add a DropTarget subkey to your Registry key that specifies the object's CLSID.
Either way, whenever your menu item is then invoked, Windows will call into your existing app instance if it is already running, otherwise it will launch a new instance and then call into it. Either way, Windows is handling all of that for you. All you are doing is providing an entry point for Windows to call into.
I would suggest the IDropTarget method, because DDE is deprecated, and because IDropTarget is more flexible. While your app is running, you could re-use the same IDropTarget object to handle OLE Drag&Drop operations on your app's UI window and Taskbar button, and support automated invokations of your scanner by other apps.

sending commands to an application from Excel? COM?

I wrote a device controller (rs232) and it is being used successfully, however users want to view data and control the device (or perhaps communicate through my program) from Excel. I dismissed DDE as an option and found that RTD (IRtdServer) is probably a good start (though no way to send data back to the "server" from the real time data client).
I found these resources for the RTD part:
http://support.microsoft.com/?id=327215
and
http://support.microsoft.com/?id=327215
This is a multi-threaded app and I had already added the ability to have multiple listeners on the com port so that I could update multiple clients. I will add the COM interface to the EXE.
But what I need after that is some way of controlling my app/proxying commands to the device through my app from Excel.
What would be the best way to do that?
Perhaps another COM interface and calling it from VBA or something? I am not familiar with using scripting from Excel, so perhaps someone can provice sample code or links that show both the code for a COM object and the accompanying VB(A?) code?
Keep in mind that this is an unmanaged C++ application and it cannot be converted to managed or C# right now. Alternatives using C# are welcome as well, but that is a long-term rewrite.
Thanks
EDIT
I have an alternative to adding COM support into the existing EXE. I think it is more flexible to add a two-way communications (cross platform - maybe boost or corba or just straight IP based with my own message protocol)
A COM server (or two) can wrap that communications channel - whatever it is. This doesn;t really affect my question at all - I still would like to know the options for controlling an external EXE from Excel.
EDIT
Not having to roll out .NET to customers is also an big plus. many of these devices are on PCs that are pretty old and have perhaps NT or XP on them and I don't relish increasing my setup/install package from 700KB to the ridiculous .NET install size...
Option #1:
Create a small COM server - make sure its interfaces are suitable for scripting with the built Visual Basic engine in Excel. (e.g. use simple types and BSTRS).
Write Excel VB Macros to (1) add your own tool bar to excel and (2) call your COM server.
You can also add buttons and other UI elements to sheets and hook them them up to VB macros.
Option #2:
I realize that you do not want to use C# - but automating office, and talking to COM objects is really, really easy in C# with Visual Studio Tools for Office (VSTO). You shoul really look into this option - If done correctly, it shouldn't mean re-writing any of your existing code. Just use C# and VSTO as a bridge between Excel and your RTD server. As with VB, its straight froward to connect UI elements in Excel to C# and then to your RTD server.
Calling a COM object from VBA is straightforward. This SO Question and my answer give an example of how to create a COM object. Calling exposed methods is as you would expect:
object.ExposedMethod(optional params...);