How to make Qt4 work using Code::Blocks in Linux Mint - c++

I'm trying to use Qt4 using the Code::Blocks IDE. I'm running Linux Mint and I'm getting some errors. I looked around and found some people that had the same problem as me, but I can't seem to get their solutions working on my computer.
I installed Qt4 using the command
sudo apt-get install qt4-dev-tools
And when I type whereis qt4, I get qt4: /usr/lib/qt4 /usr/include/qt4 /usr/share/qt4
If I select "Create new Projet" in Code::Blocks and Select Qt4 project, it asks for Qt's location, which is $(#qt4) by default. If I click next, it says Code::Blocks doesn't know the "qt4" variable and gives me a prompt to set the base location, the include directory, etc.
Since I don't have any idea as to what I should be putting in there since nothing works (either it says "QTCore cannot be found in the specified directory", or the "lib" directory couldn't be found, etc.).
I tried what was posted on this forum: http://crunchbang.org/forums/viewtopic.php?id=18210, but it didn't solve my problem and I get the same errors.
In the "/usr/share/qt4" directory, there's a link to the "include" directory, but not to the "lib" directory.
I'm pretty new to Linux and all of this, so I'd like it if the answer was very detailed explaining what I did wrong / what I have to do.

Install the QtSDK
As a first step I would advise you to download directly the QtSDK, from the project site here.
Note: You could also use the precompiled version for your Mint version,
but in my personal experience, when working with external SDK,
you have more independence in development, it also allows you to work
freely with multiple versions of Qt simultaneously without move any
dependence of your OS.
You can follow the graphics steps to install the SDK, I advise you to check the option "download source", later this is going to be used for debugging code, and if necessary will allow the recompilation of some classes.
Now your QtSDK is installed on the folder eg "/usr/local"
So, all references inside your IDE should refer to this location.
Install the C::B
You can use the version available in "Software Manager"
Configure the C::B
When we start a new project and asks the location of our SDK we indicate this directory /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc
Now the project is ready!
Note: "/usr/local" and "4.8.1" are variables depending on where
and what version you have installed.
Is very likely that your build directory, is not correctly assigned in "Settings->Compiler and Debugger->Toolchain ...->Compiler's Directory"
will be the default "usr" which should be replaced by "/usr/bin"
Now, when compiling with the standard project ".pro" and if your project has the requirement to use a "moc" tool strategy, the simplest way to do that, is use a customized Makefile, with all stages of compilation.
To learn how to make a customized makefile, you can read this answer.
And although I would advise again:
Although that CB is an optimal environment for working with wxWidgets, and C/C++ in general, I personally think that in the case of working with Qt, QtCreator provides a development environment more native and optimized to work with your projects QT.

Related

Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update configuration settings

I just want to be able to compile/run my OpenGL C++ projects on my local machine.
Do I need "nRF Connect" if I'm only pursuing local projects?
I have VS Code installed running version 1.71.0 (user setup) on Windows_NT x64 10.0.22000
I am using the mingw64 compiler located in C:\msys64\mingw64\bin\g++.exe
My active kit is GCC 12.1.0 x86_64-w64-mingw64 that is displayed on the bottom faceted pane in the window
I have my "CMakeList.txt" generated with the corresponding "main.cpp" file using the "CMake: Quick start" tool
When I run the "CMake: Build" tool, I get the error "Unable to determine what CMake generator to use". Therefor my CMake "build" directory is never created in my $(workspace)
I have tried running the "CMake: Reset" tool and I don't think that is the problem right now. In my "settings.json" file at the bottom, I see "nrf-connect.toolchain.path: " setting is set to the value "PATH". I think that is one of the issues but don't know what value to change it too. Also my environment variable "Cmake: Configure Environment" located in settings->Extensions->CMake Tools is empty for my key/value pair, also don't know what to add to that as well. I've been combing the internet for weeks so I can articulate my problem to you guys which as much of it solved before I brought the issue here. I was able to compile/run my C++ projects on VS code with no issue prior to installing CMake but am trying to build projects with OpenGL. And from what I seen CMake is one of the options that is required when it comes to building OpenGL projects.
Don't send me some documentation as a solution because I tried it and that is why I'm here. It blows my mind that there isn't a step by step on how to integrate CMake with OpenGL in VS code. The tutorials I've seen, they skip a lot of crucial steps which is the dumbest thing I have ever seen and it leaves us pulling our hair out.
CMake: Configure Environment setting

Configure kit for Qt automatically

SO!
Let's say I have a number of settings (GCC compiler 9.3.0 built from source, as the distribution I have to use has a very old one, along with environment setup) for a new Kit in QtCreator.
I have managed to setup an environment for compilation and execution of compiled binaries, and made a script to make it work (like qmake -nocache -recursive/make/sudo make install, direct execution of g++, and other stuff).
One thing that script can't do at the moment, is that it cannot create a kit for QtCreator with new compilers and environment being set as required, so after running a script, its user has to go through setting it up himself through GUI, which is bad, because this can cause misconfiguration.
This thing I'm trying to create is going to be used by around ~200 people in my company, so leaving readme.txt with instructions just doesn't go well enough for me - I don't want running around fixing missing "{" and "}" in Environment description in created Kits, and other stuff.
Are there ways to create Kits for QtCreator automatically from command line? Maybe, there's some files to edit?
I've looked into this one a few years back (I wanted to do something similar for registering Buildroot toolchains automatically in QtCreator), and I was unable to find an off the shelf solution. So i think there are 2 ways to implement this:
a) Implementing a command line utility the manipulate the ~/.config/QtProject/qtcreator/{toolchains,profiles}.xml files. Maybe by (re)using the existing C++ implementation within QtCreator, or just re-implement it ie. in Python. Back than I didn't start to work on this as there was no real business need.
b) Switching to qbs, as qbs has support for setting up toolchains from the command line ( see: https://doc.qt.io/qbs/cli-setup-toolchains.html)
If you decide to go with solution a), please let me know and maybe we can partner up to implement it.
Check out the command line sdktool bundled with QtCreator:
The SDK tool can be used to set up Qt versions, tool chains, devices
and kits in Qt Creator.
There still is a lot of knowledge about Qt Creator internals required
to use this tool!
I haven't tried it yet, but I did find the executable under Tools/QtCreator/libexec/qtcreator subdirectory of the Qt Creator installation directory. ./sdktool --help works for me under Linux.

Building wxWidgets Hello world

The wxWidgets hello world example does not provide sufficient information to build wxWidgets in any one particular environment.
The Code::Blocks wxWidgets hello world example does provide sufficient information, but it does not seem likely that a newbie, or even a quite sophisticated user, could figure out all the necessary steps on their own, because there are arcane magic words required.
The Code Yarns example uses CMake, thus could run in many particular environments, but seems to assume that you have already set up wxWidgets and compiled it for your particular environment, and there does not seem to be a CMakeLists.txt file to compile wxWidgets for your particular environment.
wxWidgets is supposed to be cross platform and cross environment, and I am trying to set up a project to compile in several environments: on Windows10 Visual Studio, Windows 10 TDM-GCC, Windows 10 Code::Blocks, Ubuntu Code::Blocks, and Ubuntu 10 gcc.
And apart from the Code::Blocks environments, having trouble. Apart from Code::Blocks, I cannot find "Hello World" examples that actually set up wxWidgets on the target so that the Hello World will actually compile and run.
The wxWidgets samples directory is not particularly useful, since the samples assume an environment, and do not describe setting up that environment and the actions that will cause the sample to build and run.
Installation guide
I know this is a old question but I struggled really hard to find a guide for an installation on wxwidgets. You can use the vckpg importer by Microsoft. Make sure you have git installed before you follow this routine. I will write this for Windows with Visual Studio 2017:
Clone the following repository to a directory of your choice:
git clone https://www.github.com/Microsoft/vcpkg
Then open up powershell (ps) (run it as admin) and navigate to the cloned vcpkg folder
Now in ps, while you are in the vcpkg folder run the following command \.vcpkg integrate install so we have a user-wide integration of the vcpkg paket manager and can #include libraries in our c++ projects
Now to install wxwidgets 32-Bit run \.vcpkg install wxwidgets --triplet x86-windows. For the 64-Bit Version run \.vcpkg install wxwidgets --triplet x64-windows
Now open up the properties of your project in Visual Studio.
For the integration of the 64-Bit wxwidgets version choose all configurations and as plattform x64. Then go to C/C++ -> General -> Additional Include Directories and add the following folderpath YOUR_FOLDER_PATH\vcpkg\packages\wxwidgets_x64-windows\include;YOUR_FOLDER_PATH\vcpkg\packages\wxwidgets_x64-windows\lib. Do the same for the x86 configuration but with the wxwidgets_x86-windows folderpath instead.
As a last step go to in the properties under C/C++ -> Preprocessor and under the point Preprocessordefinition add the following as extra point WXUSINGDLL=1 (do it for the x64 and for the x86 plattform configuration if you want to use both)
Now you should be able to use the library and run the hello world project.
To build an app, first you need to have the library compiled. To achieve that you can get precompiled binaries or the sources (see Downloads) and compile them yourself (see Building).
Instructions might still not be perfect for everyone, and you are welcome to improve them - even call it your first contribution ;)
The installation instructions that I was looking for are to be found in wxWidgets/docs/install.txt
There are multiple ways to setup wxWidgets on Windows and use it in a project.
If your project is going to use CMake there are 2 main options (other than compiling stuff yourself some other way):
Use vcpkg - which, in theory, is the easiest, but I couldn't get it to work (in time). Here is some info on that: https://www.wxwidgets.org/blog/2019/01/wxwidgets-and-vcpkg/
The problem is find_package couldn't find the package, so then I just went to 2:
Download the lastest compiled headers, libs & bins from the wxwidgets and put them in a folder like c:/wxwidgets. Then, in your Cmake file, before the call to find_package, do:
SET(wxWidgets_ROOT_DIR "c:/wxwidgets/")
SET(wxWidgets_LIB_DIR "c:/wxwidgets/lib/vc14x_x64_dll")
SET(wxWidgets_CONFIGURATION "mswd")
The LIB_DIR is using VS2019 x64 in my case.
mswd just means build this for Debug
Finally, when adding the executable, do not forget the WIn32:
add_executable(membot WIN32 ${project_SRCS})
P.S.: Remember to extract the headers include folder near the lib.

How do I set up C/C++ on Eclipse in Windows?

I just did the default Java (8) installation of Eclipse on my Windows (8, yikes) laptop, and it seems to work just fine. However, I'm not as good at Java as I am with C and C++, and for some work it's more expeditious to use C/C++ than Java.
Unfortunately, the Eclipse installer for Windows doesn't make it very easy to set up Eclipse for C/C++. It looks like I'd be fine with Linux or BSD, but then I'd have to scrounge up another laptop (because I need the mobility) and install Linux or BSD on it. Yes, I need to leave Windows on this machine, so Windows hate isn't going to help me.
My lazy web search turned up this article: "Install Eclipse for C++ Development on Windows 7 64-bit". Is there a better installation guide than that, or does anyone care to describe the process in more detail?
Even though you have CDT features installed, you need to install a GCC compiler for windows such as MinGW or Cygwin. Once you install them, add the 'bin' folder in the installed path to the environment variables and then restart eclipse. You should now see MinGW compiler when you select "Create new C Project". After this step, proceed with your C programs and this should resolve your problems.
You will have to install a GCC compiler in your PC and then link it to the project each time you create a project. This can be done while you create a new project, or even after you have done so. You can download MinGW compiler through the following link
https://sourceforge.net/projects/mingw/files/latest/download?source=files
Once you have downloaded the compiler and installed it, it can be linked through the following steps:
i. While creating a new project, choose MinGW GCC compiler in the tool chains.
ii. Once you have finished creating a project, go to Project->Properties.
iii. Look for Run/Debug Settings in the left panel.
iv. Click on the New tab and select C/C++ Application.
v. Look for Environment option.
vi. Click on the New tab.
vii. Type "PATH" in the Name bar and fill the Value bar with the path of the compiler. For me, its C:\MinGW\bin.
vii. Click on OK and you are done!
The instructions you link to have you install Eclipse IDE for C/C++ developers which will work fine to get a C/C++ development environment up.
If you would instead like to use your EXISTING installation of Eclipse and add C++ Development Tooling (CDT) you can launch Eclipse and then use Install New Software to install the C/C++ Development Tools

Create First Project in QtCreator, problems with kits

I've just switched to QtCreator for C and C++ developing. I have problem in creating first project, in particular with compiler kits I suppose.
When I go to create a new project, I have the error message that no kits is available.
As you can see, I don't know why it is shown that Qt Version is invalid. How could I solve?
You should first install your C++ compiler. You should also define your compiler in "Compilers" section. If you also want to use Qt you should set the compiler for your kit in the "Kits" section.
When you install QtCreator on MAC OS X you can find it in
/applications/qt
in this folder there is another folder called
5.2.1
Here there are all the compilers.
So to solve the issue you can either add, in QtCreator options, the path of every qmake.bin file or cut the 5.2.1 folder and paste in
/Users/YOURNAME/qt
creating qt folder if it doesn't exist.
PS: I've tried to make the directory invisible, but if I do so, I get errors using the second method