Qt - C++ Graphical application in visual studio - c++

I want to create graphical application (drawing and moving squares and so) using C++. I was suggested to use Qt library for this. I am windows user and I use Visual Studio 2013 for developing C++ (console) apps. So I typed Qt download into google hoping to find some package of DLLs, libs, headers or something like that so I could include headers and link libraries with my code. But all I found was IDE Qt Creator (which I do not want) and Qt Visual Studio plugin (which I downloaded, but it still requires whole IDE to work). So my question is - How can I develop graphical application (no forms, just "canvas" to draw on with some mouse/keyboard support) using Qt library, C++ language and Visual Studio IDE, without requirement of downloading tons of GBs for IDE or plugins I do not want, with insurance that application would be easily deployable on most common operating systems.
The reason I do not want Qt creator IDE is simple -- There is a chance for this to be semester project and will be reviewed by teacher without any extra IDEs. (I'll send him just VS project/generated Makefile and Qt libraries with headers)
Thanks for clarification.

The short answer is: you cannot. You need Qt SDK, which comes with Qt Creator.
Qt comes with qmake build system and it does not require any IDE to compile and run the application. You can write in any IDE you want and compile anywhere, where Qt SDK and compiler is available.
If you want to provide the application to your teacher, he must have Qt SDK too to compile it. There is no way around this. And better test the application in the target environment. Writing portable applications is not a trivial task - if you hardcode paths like C:\QtSDK\path\to\something, there is little chance to run it under Linux without any changes.
If you cannot expect any SDK on a teacher's computer, you have few options:
convince her to install necessary tools
ask her what tools are permitted and stick with them
bring your own computer for final evaluation

Related

Gtk3 developing on windows

I am new (relatively) to C++ and to SO.
Having stretched the creativity of console applications to the limit, my very rabid mind wants to know how to code GUIs now. I did some research, decided to use GTK rather than Qt because of having freedom of choice, there being no strings attached and something about slow internet and having to download some 0.6GB were I to go with Qt.
It has been a brutal 48 hours trying to build 'Hello World' on Gtk. This is me throwing a tantrum. I'm using Visual Studio 2010. Perhaps this is the source of all my woes. It seems Gtk is meant for C and not C++. After solving issues with header files includes and a certain notorious glibconfig.h missing (which I downloaded from the internet only to find, to my horror,that it is supposed to be a generated file), the compiler threw syntax errors,especially in one gatomic.h.
I suspect 10 errors will come up for every one I manage to solve. This is where you come in. Do you use Gtk to develop c++? If not, why so? What would you recommend instead? Do you use Gtk on windows? How is that possible? Please give details.
Is it possible to make cross-platform apps that use C++ code and a Python/VB GUI?
Your answer will be sincerely appreciated.
First off, a general note: Gtk being mainly developed as a toolkit for Gnome, I think it is fair to say that the main focus is high quality on Linux while other platforms are somewhat second-class citizens. This is probably most visible by looking at the integration with the native look and feel of Windows and MacOS. If you are looking for a toolkit which behaves equally well on all major platforms, I'd recommend you reconsidered Qt.
As far as your more specific questions are concerned:
C/C++
Gtk is written in C, and consequently has a C API. If you are looking for a C++ API, look at the Gtkmm bindings. Note that you can also use the C API in a C++ application.
glibconfig.h
I don't know whether you tried compiling Gtk yourself, but the easiest way to get Gtk3 for windows is by downloading the precompiled all-in-one bundle from http://www.gtk.org/download/win32.php (which includes the glibconfig.h you are missing).
When and how to use Gtk and with what language
As pointed out above, the primary users oft Gtk are people who develop applications for the Gnome desktop environment. Most cross-platform applications nowadays however use Qt since the quality on Windows and MacOS is higher compared to Gtk on those platforms.
Concerning what langauge to use, a strength of Gtk is that there exists bindings for many languages (including C++ and Python), so you are certainly not confined to C.
When developing with C++, something that I personally like about Gtkmm is that it uses the standard library, as opposed to Qt which has it's own implementations for data structures etc (the reason being that Qt predates the times when the STL was generally available and usable on all main platforms).
How to use Gtk: contrary to Qt which has the excellent Qt Creator, Gtk is somewhat lacking a specifically designed IDE for easy development. The closes you'll get is using Glade for interface design and a text editor or IDE of your choice for the coding, but that choice will differ depending on the platform you are on. Clearly, as you probably noticed, integrating Gtk into the environment of choice usually requires some work (and also some more technical knowledge). So again, if you are looking for an easy to set-up and use environment for developing GUI applications, I'd just go with Qt and Qt Creator.
Cross-Platform apps
First off, Visual Basic is not cross-platform. But generally speaking, there are plenty of possibilities for doing cross-application development, using various languages.
I've had to get a gtk3 project working on windows a few months ago, when gtk3 just came out for windows. I've had problems compiling it under Visual Studio as well, and posted a question here, specifically this one.
Here's how I got it working on windows:
Download the all-in-one bundle for Windows from gtk.org
Install, etc, set up include/link dirs within the project. (personally, I dumped gtk's folders in the project folder, pointed at "include" as an include dir and "lib" as a link dir, then proceeded to move any files/folders the compiler cannot find around to the root of "include" )
If not set up automatically, add include and link dirs as necessary until the compiler finds all the files.
If using MinGW to compile, it will succeed at that point.
If using Visual Studio, you have to modify gtk headers as described in the gtk mailing list:
In gutils.h lines 82 and 122, and in gstring.h line 129, change
"static inline" to "static __inline".
Blockquote
Note that the modification does not impact MinGW's ability to compile.
I have successfully compiled my gtk3 project on both windows (with either Visual Studio or Code::Blocks) and linux without writing platform-specific code that way. Just don't forget to include the required runtime dlls with the program when you ship it.

C++ Qt executable compatible with all windows computers?

I have had problems in the past using visual C++, when I ran the executable on other computers it required a .NET framework. I have now started looking at c++ Qt GUI builder and from what I have read C++ doesnt require any additional downloads apart from the executable file to be able to run on other computers, is this true? If I use Qt to build my GUI and send it to other users they will need no other external downloads?
I have now started looking at c++ Qt GUI builder and from what I have read C++ doesnt require any additional downloads apart from the executable file to be able to run on other computers, is this true?
Not necessarily; see below.
If I use Qt to build my GUI and send it to other users they will need no other external downloads?
You will potentially need to get redistributables installed on each user machine where this is needed, but this is not a Qt issue, just a generic principle how VS/MSVC and Windows work. However, there is no gentle way around to it in my understanding.
I'm not 100% sure, but I can tell you that some of my users need to download the Visual C++ Redistributable package. They would sometimes get a missing "msvcr.dll" error. Very frustrating. I tried including the file with the install, but it was picked up as a virus by some antivirus programs.

creating C++ program that runs on most of PCs

I have a project that requires writing a code for small executable file. I used visual C++ express 2010 IDE to create this file. After I finished writing the code, I tried to copy it to a couple of different PCs. It gives me an error message every time I clicking on this file to execute it. The message states that I have to install (.NET framework). I watched a couple videos on YouTube explaining how overcome this problem by changing the runtime library from multi-threaded Debug DLL (/MDd) to multi-threaded Debug (/Mtd). However; the IDE can’t debug the C++ code because when I create my project by using CLR template!
Is there any way to solve this problem? Can I create a similar program that not requires any further downloading once I using on different PC?
Is learning a different language like JAVA or C# will help creating small programs (like my program) that run on most Window platform machine?
Just use Qt - it runs on Windows, Linux, MacOS, support for Android and iOS is scheduled for this year, plus it supports embedded platforms and some of the more obscure mobile platforms. Also, support for Windows RT was just kickstarted. A complete library with tons of functionality, good documentation and lots of educational resources. It provides tons of tools, from implicitly shared containers through threading, signals and slots, 2D and 3D graphics, widgets, multimedia, sensors... and whatnot...
You can even develop commercial applications under the LGPL license.
Also comes with a pretty good IDE - Qt Creator.
You can develop standard C++ applications or use QML, which is a JavaScript like language for markup and scripting, which is used to build applications from C++ implemented components. You can also extend QML. It is much faster to develop with QML and you still get the advantages of platform native binary under the hood.
Note that you will still need to either ship a few DLLs with your application. Unless of course you use a static build, which requires you to either have your application open source, or purchase a commercial license... which doesn't come cheap...
But still, a few MB of DLLs are far better than the entire .NET framework. A static build will produce executables about 8-9 MB with no external dependencies.
Stick with the C++ standard, avoid Microsoft extensions (managed code), and call only POSIX functions of your OS, then you should be able to write portable programs.
You seem to have created a Managed C++ Project. Instead create an empty Win32 C++ project and then add in your .cpp/.h files. This will limit you to the default libraries available on all PCs with the C++ runtime. If you want to remove that dependency too then statically compile in the runtime using the /MT option. Details # http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.71).aspx
As you move ahead you would need to be conscious of what libraries you take dependencies on and what versions of the OS are those libraries available on or if you need to package them with your bits.
Both Java and C# will help making portable programs. Usually, people will have to install runtime environments for executables written in these two languages, however. These days, C++ is more portable than ever. You can easily run C++ executables in your browser:
https://github.com/kripken/emscripten
http://code.google.com/p/nativeclient/
This makes many of the reasons why Java and C# came about irrelevant.
Open standards like OpenGL also make portable GUI programming easier than ever. Try Qt, if you want to write a simple GUI in C++.
Note: It is possible to run C++ program in any computer without installing anything if you haven't use .NET framework. In your case, there can be two reasons to trigger error in target computer.
New computer doesn't have required run-time assembles.
New computer doesn't have required .NET framework installed.
..........................................
So what to do:
Before start your program you have to design weather are you going to use .NET framework support or not. If you use .NET framework when you develop your program, then you much install same or higher .NET framework in target computer.
If you no need to use .NET component then your target computer should only containing run-time assemblies.
How to get rid of .net framework
right click on the project in solution -> properties -> General -> Common language run time support -> select "No common language run time support".
..........................................
Then what you need is only relevant run-time assemblies be in target computer.
How can run-time assemblies be in new computer:
There are two ways:
Install suitable C++ disputable environment in target computer(if you use VS2008 SP1, C++ RD package should be this. Please consider the solution build architecture also (32 bit/64 bit) before download ).
Deploy run-time assemblies with your solution package. (I like this because user no need to install any third party components)
..........................................
How Deploy assemblies with my project:
for this your all DLL, LIB, EXE should use same run time version.(if not, you face troubling to redirect assemblies by 'manifest' files ).
How to check the run-time version.
open DLL,EXE by visual studio (open->file) -> expand RT_MANIFEST-> double click the file under it ->then assembly dependency details will open. -> copy the data in right column and paste to note pad.
You will see this kind of line there. and ther is the version run-time assemblies your specific DLL or EXE use.
assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86".....
After identifying the version of run-time assemblies follow this tutorial and try to run in fresh installed computer.
At last: If you think this bla.. bla.. is so complex and your program is very simple, then you can consider about "run time assemblies statically linking" (try Google). But personally I don't like this method.
good luck!

Creating GUIs for application

This is a question I've been wondering about for a long time.
How do you create an Interface for your program ?
It seems to much of a pain to position form controls and buttons using just code.
I'm looking for something similar to Visual Basic where you can drag and drop controls onto the window. But, I want to do this for applications written in C++.
Can It be done with compilers like MinGW on Eclipse ?
If you don't want to go the Qt route you can use ResEdit which is freeware. It will produce Win32 friendly .rc files that can be built with the MinGW resource compiler and used in Win32 applications.
There are some C++ Win32 wrapper libraries available though I'm not aware of any that are nearly as mature as Qt. I believe WinxGui is a port of WTL (or at least claims to be compatible with WTL) for GCC. It doesn't look like there has been much activity on the project site for a few years however.
What you're searching for is called Qt, both Eclipse and MinGW friendly.
Check out this nice article.
Qt toolkit is written in C++. So you can use it to develop GUI. It also comes with Qt Designer and Qt Creator IDE and tools.
Qt Reference Documentation
Qt Designer Manual
Qt Creator IDE and tools
And you can use MinGW to compile the code. You don't need to download MInGW separately. When installing Qt toolkik, it asks if you want to download MInGW also, just say yes to it. It will then download the correct version of MInGW itself.
The 1.7 GB download you look at is probably the full Qt SDK. This is not just Qt and documentation, but also includes the Qt Creator IDE with the Qt Designer "Form builder", the MinGW compiler, debugger, examples, demos, and some other stuff. There's also an "online installer" that allows you to select the packages you want before downloading everything. That's probably what I'd use if I were starting from scratch on Windows.

Qt in Windows: build environment and redistribution problems

I want to ask your opinion about one specific aspect of endless "Qt vs wxWidgets" question. Using wxWidgets in Windows, I may continue to work with my prefered build tools and compilers (in my case, Visual Studio). I only need to add wxWidgets include and lib directories to the compiler/linker path. When necessary, I just open some wxWidgets form designer (like DialogBlocks) and make form layout. Executables don't have any additional dependencies and don't cause any problems in redistribution.
On the other hand, Qt comes with its own IDE which tends to be the main development tool (which I don't want). It installs MinGW. It uses qmake, this is one more challenge in integrating Qt to existing build environment. I don't know how to use my existing libraries, developed with VC++, in Qt application. Can I continue to work with Visual Studio or I need to switch completely to Qt Creator? Or use both, building everything but UI in Visual Studio, and UI in Qt Creator? How Qt-based application can be redistributed: should I require MinGW installation on target computer?
How all these problems are solved - I need some directions and opinions from C++ developers working with Qt in Windows.
Edit: It looks like most promising directions are Visual Studio plugin and CMake. I found that Qt plugin supports VS2010, but it requires rebuilding Qt from the source. For VS2008 this plugin works with binary Qt installation - good enough.
You don't have to use the whole Qt SDK, you can only install the libraries for VS (or build from source, if you prefer. The pre-built libraries are for VS2008 but there is a makespec for VS2010 so you can build one yourself, if necessary) and use the Visual Studio integration.
You can use Visual Studio. There is a Visual Studio integration plugin that makes it a lot lot easier to develop with Qt in Visual Studio.
As for the wxWidgets vs Qt debate... I use both (on different projects). I have to say that I would rather use Qt - it has fewer bugs IMO and in general there is an easier workaround if you have problems with the framework (Qt4 is much better in this regard than Qt3 was because the 'pimpl' data is accessible). However, distribution is slightly more complicated with Qt as you must make sure that you have set included any plugins correctly in your distro (be sure to check that it works on a clean machine that does not have Qt installed).
You can download the Qt "source-only", take a look here for the latest version. You can build this library youself using the provided configure tool and MS' nmake...
For example, my typical build looks like this:
configure -shared -release -opensource -no-webkit -nomake demos -nomake examples
nmake
This will build release-mode Qt dlls, assumes you want to use the LGPL-license (with the -opensource flag), no webkit and upon calling nmake it will not build the demos and examples... Of course, you will have to take a look at all the possible options provided by configure
You don't have to use Qt Creator, many people use other IDEs or simple text editors.
qmake is not difficult to use, from a template config you can easily modify a project file by hand. In fact qmake will generate a basic project file for you to get started with.
Use existing libraries as you would in any other project.
You don't need to require a mingw install, you can include essential DLLs in your application directory; but this is the same problem as any other "DLL hell" problem.
If you use cmake as a build system, you can use that to generate project files for visual studio (and eclipse, and ordinary Makefiles, and ..., on any OS). Just install the cmake GUI and select visual studio [myversion] in the appropriate dropdown menu. The only thing to remember then is that you need to make changes to the structure of your project (e.g. adding files) to the cmake CMakeLists.txt files.
Setting up cmake + Qt is pretty easy, and you only have to figure it out once. Googling around a bit should get this setup running in no time.