I am working on an simple c++ application for my work that needs to run both on Windows and on Linux. When running on Windows it should display a simple GUI and when running on Linux it should use a textual UI (because the Linux computer don't use any GUI at all).
I was wondering if I could use Qt to write the app (since its cross platform) and replace the GUI usage on Linux with printouts to STDOUT using "#ifndef WIN32"?
Any other suggestions would be appreciated. The program reads some properties from an xml file and runs some tests according to those properties (access sockets, environmental vars etc.). My goal is to write a single project that would be statically compiled (to get an undependable executable) for each platform and avoid creating different projects.
Thank you.
It's certainly possible, but try to avoid #ifdefs as much as possible.
One approach is to isolate all the core features (data processing, networking etc...) in non-GUI classes. Then you write two sets of classes for presentation: one based on QWidgets, the other one that just does text input/output.
To wrap it up, use an #ifdef in you main() to select which "presentation" classes to use (and switch between QCoreApplication for non-GUI and QApplication for GUI).
Don't base that #ifdef on WIN32, use a custom variable. That way you can run and test both versions in the environment you're more familiar with.
Related
I am evaluating the feasibility of converting my app (Win32) to Qt. I would like to convert the code so that I can gradually convert one single codebase from Windows GDI to Qt, rather than cloning the source and have duplicate code. By flipping one global switch, or declaring one manifest constant in the project properties, I want to convert and test, while being able to release a production version (with the old code) whenever necessary.
Windows starts with a WinMain() function, I see that Qt has a main().
Is there an technique to organize the source to facilitate this? What is the best way to structure the code?
If "how to facilitate this" means "how to change Windows executable entry point" then
in VS project settings: "Configuration Properties > Linker > Advanced" put in "Entry Point" this "mainCRTStartup".
If you need to do that from command line then check this: Replacing WinMain() with main() function in Win32 programs
The Android application I am about to work on has the UI in Java and the non-UI functionality in C++ that would be accessed via JNI. The C++ code uses some non-UI Qt classes. I am thinking I will spawn a thread in JNI_OnLoadthat essentially will instantiate and run QCoreApplication. Any subsequent JNI call will simply post an event to this thread. Is this possible? Regards.
What you want to do is definitely possible but a bit more difficult than it seems initially.
If you build your app end to end in Qt there's a lot of functionality you get for free from their framework that allows it to run on Android and a lot of that functionality/plumbing is wrapped up in their UI. So if you're not using their UI there's extra work that you need to do.
On Android their UI framework basically creates a native Activity and then uses that activity as a wrapper for the app. If you look at the low-level source for their UI thats what's happening on Android and it's what allows the Qt app to access local resources, the network, OS facilities, etc.
Without the Activity wrapper, your app will only be able to do simple, in-memory operations that require no OS, file system, or network access and also won't be able to make use of other Qt libraries(eg Qt5Sql, Qt5Core, etc).
Here's what we had to do to make this work in our java app:
Create a proxy wrapper Activity for Qt to use that shares the base
context of your app.
Create a QtActivityDelegate.
Set the proxy activity and delegate using the native Qt android
libraries. eg QtNavite.setActivity.
Instantiate and set a DexClassLoader using the same native Qt android libraries.
Load any Qt libraries using System.loadLibrary(..). Please note that the libraries need to be present on the file system already. This part was a big pain for us.
For your Qt Code, make sure you have proper wrappers written so that they can be used via jni. We ended up using swig to auto-generate java wrappers for our code.
You can find out more about swig here: http://swig.org/
After all that you should be able to use your Qt class/library from within a native Android app.
Painful but definitely possible!
I'm writing a Qt GUI application that works on Linux and Windows.
I have been able to deploy it on Linux and Windows with supporting shared libraries of respective platforms.
It runs absolutely fine on Windows and Linux except that controls do not appear as expected on Linux when I run the deployed binaries. e.g. QGroupBox is not at all seen and buttons and text label sizes are not as I had set.
If I run through Qt Creator on Linux, controls look alright.
Are there any specific files for UI which I need to deploy along with other required shared libraries to make sure that controls look fine across all platforms?
Thanks!
Try to run you program with parameters -style windowsxp. Also you should look at QStyle and its derivatives. In several cases you'll have to write platform-dependent code, like:
#ifdef Q_OS_WIN
label->setFrameStyle(QFrame::Panel | QFrame::Raised);
#else
label->setFrameStyle(QFrame::Box | QFrame::Sunken);
#endif
statusBar->addWidget(label);
please bear in mind I am not a GUI programmer.
As the title says but to give a little more details:
I have a very large C++ application which I would like to upgrade the GUI for. There is an SDK that we can attach a new GUI onto and I would like to make it look as modern and fancy as possible, I have been advised to use HTML5 for this.
We build and link the project using in house bat files which I have hooked into MSDEV to save me going back to the console every time I want to build the project. I also use MSDEV to attach to the programs when they are running to debug.
Can I also do this in QT?
(I cannot download it and try as I need to have a business case for downloading new software and investigation is a hard one to get approved).
If I did this in QT, could I then use Webkit to create a HTML 5 front end or is there more work required?
What Does Qt Look Like
http://www.youtube.com/watch?v=bVQ0S-b5lDs
The demo program that comes with the Qt SDK shows off quite a bit of what you can do with the GUI programming. You can build almost anything you can imagine!
It looks native to the operating system it is running on, Windows 7, Mac OSX, Ubuntu, etc.
I believe most of the Linux KDE GUI is now done through Qt.
Running Console Applications
If you need to run things from the console, you can manage that in C++ pretty easily.
system("run_this.bat");
In Qt, if you don't need to see the console window, you can run most things as a QProcess.
There are ways to hook the stderr and see what is going on as well.
HTML 5
Something written in HTML 5 shows up in a browser, and there are a number of slick graphics and effects that can be used with it, but using the QtWebKit, will only ensure that the webpage you are rendering looks the same on every computer you run it on. Most modern browsers are becoming HTML 5 compliant, so relying on the HTML 5 out of Qt shouldn't be necessary.
W3Schools gives a pretty good introduction into what HTML 5 adds to websites:
http://www.w3schools.com/html/html5_intro.asp
Using HTML 5 or C++
Writing a web application that uses HTML 5 versus writing a Desktop application that uses a native GUI are two very different things.
Running files on a local machine is pretty sandboxed when going through a browser with HTML 5. If you are okay with running something remotely on your own server, then it shouldn't be too bad.
I'm trying to create some kind of a server which allows me to start Qt's applications on remote machine via web browser.
I'm wondering it is possible to change/hide some symbols from Qt library (I thought about QApplication or QCoreApplication) without making any changes in code of application (I assume that it is already compiled and uses Qt shared library) and compiling my whole tailor-made Qt libs?
The reason why I need to do this is because I want to install my own specific EventFilter to QApplication and also be able to push my own created events to Qt application.
It also would be great if the solution could be used on all platforms :D
P.S. I know that it will not be possible I could subclass QApplication and modify all Qt apps to use my derived class but I would like to do this more craftily. ;-)
The tool GammaRay does all kinds of injecting code into Qt methods at runtime to attach and debug running Qt applications. You might want to have a look at its code base to see how it is done.