Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,195,311 members, 7,957,810 topics. Date: Tuesday, 24 September 2024 at 08:55 PM

Hope For C++ Newbies: Gui Toolkits - Programming (4) - Nairaland

Nairaland Forum / Science/Technology / Programming / Hope For C++ Newbies: Gui Toolkits (17236 Views)

How To Create A Simple Calculator Using Java Programing Language GUI / What Development Chain Do You Use For C++? (2) (3) (4)

(1) (2) (3) (4) (Reply) (Go Down)

Re: Hope For C++ Newbies: Gui Toolkits by peterincredible: 9:14am On May 02, 2016
pls i have a problem i created a client and server application following the fortune server and client example in qt doc but my client application is not connecting to the sever so therefore it cant recieve data from it pls any help is it bcause it is not connected to the internet or what pls i need ure ideas pls
Re: Hope For C++ Newbies: Gui Toolkits by GregoryOla: 10:22am On May 08, 2016
I build and run those samples everytime I upgrade to a new wxWidgets release

I honestly have no idea what you did wrong, but for the benefit of doubt I will post a guild to building wxWidgets and using it with codeblocks on Microsoft Windows


@BlueMagnificent

Should we still be expecting the guide/guild?
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 2:11am On May 09, 2016
GregoryOla:



@BlueMagnificent

Should we still be expecting the guide/guild?

Sure! Sorry I've been choked up a bit for a while
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 9:17am On May 14, 2016
Sorry for the delay but here comes the tutorials on building wxWidgets on windows using MinGW and using it with codeblocks to build a simple GUI application
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 10:26am On May 14, 2016
wxWidgets Tutotial With Codeblocks (MinGW)

This tutorial will show us how to build wxWidget with MinGW and use it with codeblocks IDE on Microsoft Windows.

What You Need
1. MinGW: To be on a safe side get one of the recent releases, it should be C++11 compliant. The chances are that any recent one you get will be compiant
2. CodeBlocks: I'm using v16.01 for this tutorial, but v13.12 and even older versions works as well
3. wxWidgets: I would be using wxWidget v3.0.2 any other one still works. To be in synch with this tutorial, when you've gotten wxWidgets' .zip or .7z file, extract it to C:\wxMSW

Since wxWidgets is mainly distributed as source, we will need to build it into a library before we can start using it to develop applications. Building might seems daunting at first but it's very easy.


Setting up The Build Environment

Open up windows command prompt and navigate to C:\wxMSW\build\msw or ${your_wxWidgets_directory}\build\msw
Next is to add the bin directory of your MinGW installation to the system PATH environment variable. This directory resides in your MinGW installation directory. On my machine it's
C:\MinGW\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin

to be sure its the bin directory you should see g++.exe and gcc.exe in it

Type the below line into cmd and press enter to add it
SET PATH=%PATH%;${your_mingw_bin_path}

where ${your_mingw_bin_path} is the full path of the bin directory just like mine, as stated above

With that done, we are ready to build wxWidgets


Building wxWidgets

Still in that same command prompt type in the following build configurations on the same line separated by space
(I intentionally broke it into multiple line here so that people on mobile devices would not have the line wrapped oddly)

mingw32-make -f makefile.gcc
USE_XRC=1
SHARED=1
MONOLITHIC=1
BUILD=release
UNICODE=1
USE_OPENGL=1
CXXFLAGS="-fno-keep-inline-dllexport -fpermissive -std=gnu++11"

Permit me to quickly go through some important options above:
SHARED=1 simply means we are building wxWidgets as a dynamic linked library (dll) as against a static library
MONOLITHIC=1 informs the build that instead of having the respective components of wxWidgets built as seperate dlls, link them all together as one "monolithic" chunk
BUILD=release means we are building a "release" version and not "debug"
UNICODE=1 naahhh! this is self explanatory

On pressing the enter key MinGW begins building wxWidgets. Now get a cup of coffee, tea, or even cold water because its going to take time. On a fairly decent machine it should take up to 30 mins. Just go ahead and do something else but keep an eye on the build.

When all is done you would know the build was successfull if there is no build error reported on the console. Now check C:\wxMSW\lib\gcc_dll there should be .a and .dll files present in it. Most importantly verify that the files libwxmswXYu.a and wxmswXYu_gcc_custom.dll are there, where "XY" in the names represent the wxWidgets version number X.Y.Z. If yours is v3.0.1 or v3.0.2 then "XY" will be "30" making the files
libwxmsw30u.a and wxmsw30u_gcc_custom.dll. If you are using wxWidgets 2.8.* then they will be libwxmsw28u.a and wxmsw28u_gcc_custom.dll.

If these files are not present it means the build did not work out well. Verify the build configurations and ensure you keyed in the right things. These files are the wxWidgets libraries you would use in build your GUI applications.

Assuming everything went well, we'll proceed to use our newly built wxWidgets library in codeblocks to create a simple application.

Setting up CodeBlocks

First of all ensure that your MinGW installation is also the one used by codeblocks to build applicatioins. To do that open up codeblocks click on "Settings" menu and select "Compiler..." submenu.
This will bring up the "Global Compiler Settings" window, at the groupbox labeled "Selected compiler" click the dropdown list and select "GNU GCC Compiler". Click the "Toolchain executables" tab and within the "Compiler's installation directory" groupbox ensure that the path displayed in the textbox is the path of the directory in your MinGW installation that contain the "bin" folder.


Next step is to set "wx" as a global variable in codeblocks. Still on the "Settings" menu, select the "Global variables..." sub menu. A window titled Global Variable Editor will display.


This window has three sections; One top section and two bottom sections. The top section has two rows each of which contains a text label specifying what the row is for, a drop down list, "Clone" button, "New" button and "Delete" button. The first rows has the label "Current Set:" while the second (lower row) has "Current Variable:" . For the Two bottom section, the bottom left has the header "Built-in fields:" and the bottom right "User-defined fields:".

Back to the top section. On the first row with the "Current Set:" label, select "default" from the dropdown list. On the second row ("Current Variable:" ) , click on the "New" button, a small window comes up prompting you to enter name for the new variable. Enter "wx" (without the quotes) into the text box and click "OK". The dropdown list of this second row should now have "wx" automatically selected. Head over to the bottom left section that has "Built-in fields:" header. At the text box labeled "base" enter the directory of your wxWidgets installation, in our case C:\wxMSW , there is also a browse button beside to aid you. Click close and lets move on


Creating And Building A Project

Its time to create a wxWidgets project. This project is going to be based on codeblocks simple wxWidget project template.
On the "File" menu select "New" >> "Project..." . Among the project templates that are displayed select "wxWidgets project" and click go. The wxWidgets project wizard shows up, click next. You should on a page that says "Please select the wxWidgets version you want to use".


This gives you room to select the version of wxWidgets that you have, it also helps codeblocks determine the type of link libraries to look for. Select the category yours falls into. For those whose wxWidgets version is 3.1.0 and codeblocks version 16.01 (the latest) or earlier, you'll notice there is no provision for your version of wxWidgets here, simply select "wxWidgets 3.0.x" , we will table your matter later. Click Next.

This new page should be asking you about the name of your project and the folder you want it to be created in, I'm going to name my project "wxNairaLand". Select the necessary things and click next.

Fill in the text box for author name, and the rest and click next.

On this page saying "Please select your favorite GUI builder to use" at the "prefered GUI bulder" groupbox select "wxSmith" and
at the "Application type" groupbox select "Frame Based". Before clicking next lets explain somethings here. wxSmith is codeblocks wxWidgets GUI builder, it gives you the ease to drag and drop controls while building the application. wxFormBuilder is another GUI builder for
wxWidgets and also has some amazing properties. Unlike wxSmith that is bundled together with codeblocks, wxFormBuilder is a standalone application though it can be called from codeblocks if installed on your system.
In order to keep this tutorial simple we will go with wxSmith. Click next.

The first line of sentence on this next page should be "Please select the location of wxWidgets on your computer". At the textbox labeled "wxWidgets' location:" type in "$(#wx)" (without the quotes).



Since we had earlier added "wx" to codeblocks environment variable, any reference to it in the form of "$(#wx)" will resolve to the directory path we specified while setting it up, in our case C:\wxMSW . Click next.

Select "GNU GCC Compiler" from the compiler dropdown list, tick "Create Release configuration:" and click next.

This import and most times last page of the setup is where you inform codeblocks about the type of configurations you used in building wxWidgets.
At the "wxWidgets library settings" groupbox, tick "Use wxWidgets dll" , "wxWidgets is built as a monolithic library" , "Enable Unicode" . Make sure nothing is ticked at the "Miscellaneous settings" groupbox. Click Next and codeblocks sets up the project for us.

EXCEPTION:: If your wxWidgets version is 3.1.0 and codeblocks is 16.01 or earlier, a warning prompt will show up saying something like "A matching Release Configuratio cannot be found in the wxWidgets directory you specified..." . Well, ignore it and click yes as I said we'll handle the issue.

You should see a wxSmith interface showing a default frame already created for you as part of the wxWidgets codeblocks template.

Now if you built one of the recent versions of wxWidgets, you might have to add "-std=c++11" to the compiler flag. To do that, click on "Project" menu and select "Build options...", this bring up the "Project build options" window .


Right under the "Selected compiler" groupbox, there are sets of tabs. Select the "Compiler settings" tab and then the "Compiler flags" tab. Look for any row saying someting like "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]", and tick the box besides it. If you can't see such row then click on the "Other compiler options" tab and add "-std=c++11" (without the quotes) as a new line. When all is done, click the ok button.

Go ahead and build the project it should build successfully (For those whose wxWidgets version is 3.1.0, check below for how to set up the library) Run it and the window shows up having menus of "File" and "Help".


Now you can start creating wxWidgets applications using codeblocks.


wxWidgets Veriosn 3.1.0
The latest stable release of codeblocks as at the time of this writing (v16.01) does not yet have selection option for v3.1.* in the wxWidgets version selection page. The most logical reason being that codeblocks v16.01 came out before wxWidgets reached version 3.1.0. But that is not a problem in our case until you try to build and the linker complains "cannot find -lwxmsw30u" . This is expected. Since we selected "wxWidgets 3.0.x" as our version in the project setup wizard codeblocks assumes our library's "XY" would be "30". To fix this click on the "Project" menu and select "Build otions..." sub menu. On the "Project build options" window that appears at the left hand pane you should see your projects name and under it a sub tree node named "Release".
Select the "Release" node and click the "Linker settings" tab. In "Link libraries" groupbox you should see a listbox with "libwxmsw30u.a" as an item.


Select the item and click the "edit" button below. In the textbox of the "Edit library" window that shows up you should be seeing "libwxmsw30u.a" there, rename it to "libwxmsw31u.a". Click ok and also click ok for the "Project build options" window. Now your project should build


Pheww!!! grin

Any problem encountered? Just let me know
Re: Hope For C++ Newbies: Gui Toolkits by GregoryOla: 10:57am On May 14, 2016
...
Re: Hope For C++ Newbies: Gui Toolkits by GregoryOla: 12:12pm On May 14, 2016
@Bluemagnificent

A standing ovation to you sir, this looks like a well thought out tutorial. God bless you real good.

I'll go through it several times to make sure I'm in tune.

Hope I won't be asking for too much sir, but I would like you to also show how one would run the samples that come with the wxwidgets package. (Please if you can give a guide using two samples that would be splendid).


Thanks again sir!!!
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 12:49pm On May 14, 2016
Sure, your questions are welcomed grin

For the samples, that's very easy, I'll work on it right away
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 8:12pm On May 14, 2016
Building the Samples

This is a much simpler process. So long as the first tutorial worked for you, then this one should work as well.
We will be building all the samples at once, yes you heard me right, at once. But we won't be using Codeblocks, we will directly use
MinGW through the command line. If this sounds strange just remember that was also how we built wxWidgets in the previous tutorial.

So just as before open up the command prompt, set MinGW bin folder to the PATH environment variable
SET PATH=%PATH%;${your_mingw_bin_path}

Now navigate to the samples folder of wxWidgets directory, if you are in synch with this tutorial it should be C:\wxMSW\samples. Key in our wonderful build
command which has a bit of addition
mingw32-make -f makefile.gcc
USE_XRC=1
SHARED=1
MONOLITHIC=1
BUILD=release
UNICODE=1
USE_OPENGL=1
CXXFLAGS="-fno-keep-inline-dllexport -fpermissive -std=gnu++11 -Wno-narrowing"

Let me explain two things inside CXXFLAGS. -std=gnu++11 flag tells the C++ compiler to use the C++11 ISO C++ language standard with some gnu extensions permitted. Well, just know that latest releases of wxWidgets need this compiler flags to build successfully on Windows using MinGW. For -Wno-narrowing, to cut it short, it helps some of the samples build. But the long story is that when a narrowing conversion occurs, maybe from double to float, and a change of value or loss of precision of data might occurs, then the compiler is to notify that the program could possible be ill-formed. Unfortunately this notification has since been reported as error starting from GCC v5 . You can read more about it here https://gcc.gnu.org/wiki/FAQ#Wnarrowing . Unfortunately some samples in wxWidgets are caught up in this that's why we have that flag to disable the notification

Press the enter key and let the samples build. wxWidgets v3.0.1 has around 100 samples, so be patient it will take a while to build.
When its done you should have the samples built. For each sample, browse into its folder, you should see a new folder named "gcc_mswudll" . In this folder is the built application.

Remember we built our wxWidgets with SHARED=1 configuration, meaning we built it to be dll based. What this implies is that the dll would have to be in the same path as our application before the application can run. So for the applications to run successfully you'ld have to copy the wxWidgets dlls into the folder, in our case "wxmsw30u_gcc_custom.dll" and optionally "wxmsw30u_gl_gcc_custom.dll" (mainly for openGL samples). Like wise if you intend to deploy your application to another machine these dlls should equally be bundled together with your app.



CAUTION DO AT YOUR OWN RISK:: Development Purpose Only
(If you don't understand anything in this section then you better not try)

We wouldn't want to be copying wxWidgets dlls into all the 100 and something samples just to run them. To make this easy for us we will add the dlls to a folder that would have global visibility, thanks to the system PATH variable
Create a folder "C:\Custom_Env". Copy both wxmsw30u_gcc_custom.dll and wxmsw30u_gl_gcc_custom.dll (or whatever yours is called) into it.
Next, read this aricle http://www.computerhope.com/issues/ch000549.htm to add "C:\Custom_Env" to your system PATH variable. Do it with utmost care

Now you should be able to run the samples without needing to be copying ddls up and down



Building the Demo
wxWidgets distribution comes with some demo applications located at C:\wxMSW\demos . To build these demos just follow the steps described above for building the samples , that is:
open command prompt and navigate to C:\wxMSW\demos
SET PATH=%PATH%;${your_mingw_bin_path}


Enter the build configuration, all on the same line separated by space
mingw32-make -f makefile.gcc 
USE_XRC=1
SHARED=1
MONOLITHIC=1
BUILD=release
UNICODE=1
USE_OPENGL=1
CXXFLAGS="-fno-keep-inline-dllexport -fpermissive -std=gnu++11 -Wno-narrowing"


press the enter key and it builds. As easy as ABC. Go through the demos and see what they do
Re: Hope For C++ Newbies: Gui Toolkits by Nobody: 7:16pm On Jun 03, 2016
so you need the os and the tools to build and compile qt application .


Visual Studio 2015

Xcode 7 for ios

Xcode 7 for OS X 10.6 and 10.7

Qt Creator 3.5.1 for Ubuntu

Using qmake on GNU/Linux

@bluemagnificent
Re: Hope For C++ Newbies: Gui Toolkits by GregoryOla: 8:01pm On Jun 14, 2016
...
Re: Hope For C++ Newbies: Gui Toolkits by Drguzzykola(m): 2:37am On Nov 10, 2019
jereal:
@BlueMagnificent... Great job you're doing here... I remember a while back when I was trying to setup wxwidget too, anyway, I ended up going with Qt. its been great so far and I've been working on a project for a while now. But I'm having some difficulty achieving what I want with QPrintPreviewDialog... I'd post snippets if you can help me out.


Morning bro..

please help me out, downloaded At creator with the tutorial videos.

trying to create new project but got stocked in the kit wahala,

@No valid kit found..

entered the option and couldn't get any solution even with my online search..guess something is wrong somewhere.


cc bluemagnificent

Re: Hope For C++ Newbies: Gui Toolkits by danilmo: 9:44pm On Nov 28, 2019
BlueMagnificent:
BUILDING WXWIDGETS FROM SOURCE

In reply to a request made by one of us I will describe how to build wxWidgets from source using both MinGW and Visual Studio, and also how to use it with Code::Blocks IDE.

I assume that you are using a windows machine and that you've downloaded the source for wxWidgets either as a zipped file or as an installation. Note that both the zipped packaging and the installation packaging of the source are the same thing its just a matter of packaging grin. Unzip (or install) the package to a directory, preferably something like C:/wx. When you are done you see sub directories like build, demo, lib, src, etc in it, navigate to C:/wx/build/msw.
Building for Visual C++ is very easy. Already contained in this build/msw directory are solution files for the supported versions of Visual Studio. All you need do is to simply start up the required solution file, select the build configuration of our choice and build. As simple as that.

But on MinGW, the game is a bit different. First of all you should have MinGW installed in your system (I believe you've already done that). Open up your windows command prompt and navigate to C:/wx/build/msw. Next add the bin folder of your MinGW installation to your build path. This folder in usually in a directory structure like this C:/MinGW/bin (that is assuming you have MinGW installed at C:/MinGW). To add it to your build path, still on your command prompt, type the following followed by enter key
set path=%path%;C:\MinGW\bin

Do not forget to replace "C:\MinGW\bin" above with the appropriate directory path of your MinGW's bin folder.

Before we go off building it is important to understand that wxWidgets has several configurations you can build it as, I will list some of the important ones below:

BUILD > either build a release build or a debug build
SHARED > either to build as static lib or dynamic lib (DLL)
MONOLITHIC > either to build as a large junk of library containing all modules or build the individual module as separate small library
UNICODE > either to use Unicode character encoding or not

For this post we will be building a release monolithic unicode DLL library.

Still on your command prompt enter the below just to make sure the coast is clear of any previous build:

mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 USE_OPENGL=1


Next enter the following:
mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 USE_OPENGL=1


Its going to take quite some time, so I will advise you to seat back and relax (a couple of drinks won't be bad wink). When its done building and no error was indicated, close the command prompt and head to C:\wx\lib\gcc_dll you should see your built libraries staring back a you grin.
If it didn't build post the error messages it gave lets sort it out.

Linking To Codeblocks
Its assumed that your version of codeblocks is version 13.12
Open up code blocks and go to File Menu > New > Project , select wxWidgets and attend to the wizard page questions as follows
First Page > (skipped)
Second Page > Select your wxWidgets version which in our case is wxWidgest 3.0.x
Third Page > (your can handle this)
Fourth Page > (you can also handle this one)
Fifth Page > make your choice depending on what you are building, Its most likely going to be wxSmith and Frame Based
Sixth Page > Your wxWidgets installation directory (for this post that will be C:\wx).
Seventh Page > For compiler select GNU GCC compiler and only check "Create Release configuration"
Eight Page > besides the default values here, make sure the following are also checked : "Use wxWidgets DLL", "wxWidgets is built as monolithic library" and "Enable Unicode"
Ninth Page > Ensure that "GUI Mode Application" is selected

You should have a wxWidgets project generated. On building this project and running it you should see a very boring window grin


Boss please I kept having this error message wen I try to Run after installation as outlined above.


Beside , I DM u, I ll really like us to meet , discuss about a heart project, though I'm still an undergraduate, just can't wait to finish soon but before that, setting my materials for a kick start is what I've been up to for now. and I can say there is progress. will really like to meet u. if u won't mind ,help holla @08113316697 on WhatsApp

Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 1:59am On Dec 03, 2019
danilmo:



Boss please I kept having this error message wen I try to Run after installation as outlined above.


Beside , I DM u, I ll really like us to meet , discuss about a heart project, though I'm still an undergraduate, just can't wait to finish soon but before that, setting my materials for a kick start is what I've been up to for now. and I can say there is progress. will really like to meet u. if u won't mind ,help holla @08113316697 on WhatsApp

Hello danilmo, sorry I've been out of reach for a while now.
I see the error you are getting and would like to know if you actually built the wxWidget library before using it
Re: Hope For C++ Newbies: Gui Toolkits by danilmo: 7:50am On Dec 03, 2019
BlueMagnificent:


Hello danilmo, sorry I've been out of reach for a while now.
I see the error you are getting and would like to know if you actually built the wxWidget library before using it

oh. Uwc Sir
I did build. walahi. the installation has given me plenty headache, I just choose to leave it for the mean time, thinking of trying my luck with Qt though just that its about 3.7Gb shocked , kept me calm till wen I b ready for such data.

or rather, kukuma wait till I ll meet a professional to do it for me just to..
Re: Hope For C++ Newbies: Gui Toolkits by BlueMagnificent(m): 11:44am On Dec 03, 2019
Just to be sure, did you also build the sample projects included in wxWidgets distribution? if you did are they running well without issue?

1 Like

(1) (2) (3) (4) (Reply)

ALX Virtual Assistant Program / Javascript With NodeJS / Learn Java Programming Here Easily

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 87
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.