Here is my situation:
I'm developing a C++ application in Creator/Designer with Qt 5.6 on Windows 7 64-bit
I'm designing a skeleton GUI that doesn't do much on its own. It mainly provides a mechanism to integrate engineering tools built by other developers (Plug-ins if you will, not to be confused Plug-ins to Qt itself). The skeleton will be installed on workstations around the office, and it should be able to pull these Plug-ins from a network location and install them to the skeleton without recompiling. On startup, the skeleton should read its list of Plug-ins and build its menus, toolbars, and UI Widgets accordingly.
So the question is ultimately this: Does Qt provide a way of adding .ui files and associated code to a QMainWindow at run time?
Can it do so in such a way that the skeleton will not have to be changed, recompiled, and re-deployed whenever new Plug-ins are created?
Close, but no cigar: Here is an example of a calculator UI created in Designer being pulled into another program dynamically, but it appears this method uses the .ui file only. In other words, the boxes and buttons are pulled from the .ui file, but its logic is implemented in the "skeleton." I need to do something akin to embedding the calculator as its own fully functional Widget at run time.
Side question: If there isn't a nice mechanism provided by Qt, are there disadvantages to having the other developers compile their Plug-ins as DLLs for my particular case?
There's some basic misunderstanding of what a Qt application does. Every single widget you're seeing is instantiated by executing C++ code - it is all done dynamically, at runtime. The uic takes a foo.ui file and turns it into ui_foo.h. That defines a class that can populate a base widget with children.
You can use the QUiLoader to parse a .ui file and instantiate its objects at runtime, but there's little point to doing that since the other code is still C++, so it's simplest to have a plugin project that converts .ui files into C++, then compiles those along your other code and links them into a plugin dll.
The plugins are simply .dlls, ideally providing functionality consumable by the Qt plugin system, that have all the code needed: the code the comes from .ui files via uic, and the code the plugin authors wrote by hand. A plugin is an object factory: it will create QObject instance(s) that can then provide your skeleton with all the widgets and other objects it needs.
That's all. The plugins are .dlls, and you're of course free to download them from a network location to a cache folder, and open them at runtime.
There's no difference between plugins "to Qt itself" and plugins to your application: Qt is C++ code, just as your application is. While it can consume the functionality of some plugins, the rest of them are for your code to consume.
For inspiration, you should look at the sources of Qt Creator itself. It is a completely plugin-based application, the core is a plugin container that doesn't do much. Probably you could reuse the Qt Creator core as the basis for your application, with either no changes or very minimal changes. It would come with a network discovery plugin that gets the remaining plugins from the server and into the cache, and then loads them up. Such a plugin can be probably written in 150 lines of code, excluding the minimal boilerplate :)
Related
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.
I have a task to automate Qt QML based desktop applications through open source frameworks. I am completely new to testing and also to Qt QML. I am good with Java and Python and also Javascript.
Can someone please suggest a way to write automation tests for Qt QML desktop application?
Can I code things to read the elements and widgets in the Qt QML applications?, So I can validate various cases.
If so, are there any tutorials or sample automation test projects for Qt QML applications?
Have a look at Spix. Once you link against it, you can remote control your QML UI by sending fake events, either from C++, or from a script using RPC. Any scripting language that supports XML-RPC, like python, can be used.
This way, you can automate and test your Qt/QML application.
Objects are identified by paths, so you don't have to deal with coordinates. Spix finds the item by the objectName property set in QML.
You can also query object properties from the script...
The library is fairly new and under development, but I think it already covers a lot of the more common use cases in desktop apps...
I'm working on a project to develop a web application for controlling some machinery and visualising sensor data. It is deployed on a single board computer running a custom linux distro. We have a large existing code base from a previous version of the project that is based on a standalone Qt app. With the new software we are moving towards a web based interface using Wt.
At the moment we are trying to re-use the Qt code which interfaces with some system services, while hosting and interfacing with the new Wt GUI. The Qt app and Wt app are launched on different threads. Wt on the main thread and Qt on another thread. Using the c++ "thread" library to do so.
I have very little experience in Qt and there seems to be very little existing documentation on integrating the two, does anyone know of any conflicts that may occur between Wt and Qt in general, or specific to this situation.
So far it seems to be running ok and playing nicely, but I am simply trying to cover all my bases. I am looking for comments or thoughts on the situation that may identify any weak points in running the 2 apps on the same system.
Thanks in advance for any help.
Wt includes an example in the examples directory, wtwithqt, which explains how Wt and Qt can be made to work together. It includes an implemenation of one particular strategy to make Wt fit in Qt's quite specific threadming model.
I've just downloaded a copy of QT to evaluate if it will work for a project. My first goal was to create a library that contains a dialog. The goal is to see if QT supports the ability to create modules that can be loaded into various programs. Similar to the way you can create a .dll in Windows and place resources inside.
Is this possible (or reasonable) to do in QT?
If so, how? If not, what options are there for creating reusable QT modules?
Yes, it is definitely possible to have Qt dialogs within a shared library but there are caveats. The biggest issue is that you need to have a full QApplication event loop running, which is costly to start and maintain each time you want to call a Qt-based dialog, and also means an increased amount of libraries to distribute.
I'm a little new to Qt. I have been programming in C++ for quite a while.
I want to create an application in Qt/C++ just because it's very easy to create the GUIs. I wanted to know that is it possible that I can write a C++ class in native C++ and use it in my Qt application.
I want to write the GUI in Qt and do all processing using my native C++ code rather than Qt/C++. Is it possible to compile a DLL in native C++ and then load and use it in QtC++ application?
I really want to write a GUI application using C++.
There is no such thing as "native C++" as opposed to "Qt/C++", so the question makes little sense. All of core Qt code is compiled native C++, just as any C++ application that uses Qt is.
As JBentley has duly noted:
[You may be] confused because of the code generating tools Qt uses, like moc [or uic]. Those don't mean that C++ compiles natively while Qt doesn't. All those tools do is provide a convenient way to produce a lot of boiler code that the framework relies on, so that the programmer can pretend they don't exist and use things like Qt's slots and signals. The final code which you compile and link is ordinary C++, with calls into the Qt library (also C++) which you've used.
If what you're asking is "am I forced to use Qt classes in all parts of my application", then no - nobody's forcing you to do that. If you already have parts of your application written using boost, or standard C++ library classes, it's fine.
You have to understand that Qt has modular design and provides a lot of non-GUI functionality. You can use the non-gui modules in the non-gui part of your code. It's a fairly clean and general purpose application development framework. It's perfectly fine to use it for various internet server applications, for example.
The following Qt modules are of note for non-gui development:
Core: Core non-graphical classes: containers, event loop, timers, threads, state machines, internationalization, XML, json, file I/O - all of it portable.
Network: Classes to make network programming easier and more portable. Includes secure sockets, HTTP requests, etc.
SQL: Classes for database integration using SQL.
You are able to use any C++ code you would like. I have have actually had questions with the same thought process in my day to day work. First you need to grok the idea that Qt uses normal C++ and special tools to create a robust set of libraries.
Later on come back and you will want to learn more about the items below:
Signals and Slots
This is how events are wired together.
One objects sends a signal and all connected slots get called with the given parameters.
Signals and slots are an example of the Observer Pattern.
Designer Forms
The form designer lets you lay out controls using simple drag and drop operations.
The .ui file gets transformed into C++ code as part of the build process.
Layouts
You can do a lot of things with just the horizontal, vertical and grid layouts
Spacers
You can push things up, down, left, or right using different types of spacers
They look like a spring on the form designer.
Resource Files
Lets you embed graphics and other content directly into the application.
Models, Views and Delegates
Hard to avoid if your have a non trivial UI
There are other things too, but knowledge in these areas will let you make some decent desktop applications. My favorite reference is older, but still a goodie: "C++ GUI Programming with Qt4" http://www.amazon.com/Programming-Edition-Prentice-Software-Development/dp/0132354160
Yes QT4 is "old" and QT5 has been out for some time... but the book provides a solid foundation that you will be able to add information to.