Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

Qt (11)-2 How to create Qt Windows application with Qt Creator and MinGW.

Published on| May 28th, 2010 | No Comment.
Description:
Previously, Qt (11) How to debug with Qt Creator and VC++ Compiler. > In VC + + and Qt Creator combinations, we briefly. This time, Qt Creator MinGw and would like to explain briefly.

This combination, Qt recommended? Qt Creator or rather has become a standard combination. However, Qt Until the 3.5.x, GCC3 system was standard, 3.6.x Until, GCC4 system is now standard. Both, GCC3 system / GCC4 system is supported both, 3.7.x from, GCC3 will be supported out of the system.

Now, here, Windows systems in GCC3 / GCC4 caution when dealing with a system, GCC would like to describe the version strings and source code.

Before you begin, here is work, GZ, 7z to unzip the files must be compressed and, download 7z 7z download from, you should install.

Download Qt Creator: Http://Qt.nokia.com/Downloads
At the bottom "Qt Creator IDE" and I have, please download it from there.

Download MinGW: Http://Sourceforge.net/Projects/Mingw/Files/
First, MinGW to install the.

From the previous installation, download the latest Furusettoappufairu.
If the current 2010.05, MinGW-5.1.6.exe be.

Mingw shared library needed for the iconv character set conversion download and keep.
If the current 2010.05, following a set of files.

From the above three files are required at least. If 整Etai and development environment, all you need.

Then, GCC3 case series, download the following files.
GCC3 system is built 20060117-1 minutes to download. 20060117-2, and 20060117-3, there is a newer build, this is to prevent the conversion of character code. Here, 20060117-1 Please note that to use in building.

The downloaded file and all, MinGW will unzip to overwrite the installation.

From the above two files are required at least. If the environment is 整Etai other languages, all you need.

Then, GCC4 case series, download the following files.

The downloaded file, the following order, all, MinGW will unzip to overwrite the installation.

  1. 4.4.0 Full Package System GCC4
  2. 4.5.0-1 system GCC4
    5 files from the above require at least. If the environment is 整Etai other languages, all you need.
  3. Libraries and other necessary

Then, MinGW Set up environment variables for compilation.

The downloaded file, the following order, all, MinGW will unzip to overwrite the installation.

  1. PATH where to install the MinGW \ bin to add the path.
    Example)
    PATH =% PATH%; c: \ MinGW \ bin

After setting this up once, C + + let's compile.

For example, the following code (sample.cpp) Prepare.

1
2
3
4
5
6
7
#include <stdio.h>
 
int main ()
{
	printf("%s", "abc漢字");
	return 1;
}

The above sample code c: \ mingw \ bin directory and that you type the following commands can be compiled.
Executable at this time, "sample.exe" will be.

c:\mingw\bin > g++ -o sample.exe sample.cpp
               : Error information will be displayed here if there is any errors. 
c:\mingw\bin > 

Executable file that was created "sample.exe" Let's run.

c:\mingw\bin > sample.exe
               abc漢字
c:\mingw\bin > 
Let Qt Creator to the latest version.

Here, Qt Creator binaries are OK. The latest version (currently 2010.5, 1.3.1) Download and install it.

Most just follow the onscreen instructions to install.

Should be noted, MinGW is not installed.
Use MinGW installed first.
Are included MinGW is, GCC3 system / GCC4 regardless systems, encoding the source code, the literal string and UTF8 unless the section will be a problem here, please note that the installation .

Therefore, the first four-screen installation "MinGW" 外Shimashou check.



Then, Qt Creator Start, Qt Library Sets.


The Tools menu (T)] - Options (O)] Selected.

Here, from the left tree, Qt4 - Qt Version menu.
Appears to auto-detect the right, in that time you want the Qt library (SDK) if you have the path, select it.
If not found, select the document, click the + button on the right. From child items are displayed, select it, bottom right

  • Sets the version name as the title. (For example: 4.5.3 MinGW)
  • This path is QMake, Qt library (SDK) installed path (for example: C: \ qt \ 4.5.3 \ qt \ bin) set.
  • This is the path to MinGW, MinGW installed first path (for example: C: \ MinGW \ bin) set.

Finally, the default version of Qt bottom right, select the name set in the previous version, click the Apply button.

Then specify the debugger.
From the left tree, debug - Gdb selected.


Gdb on the right path, Gdb the full path to the executable file. (For example: C: \ MinGW \ bin \ gdb.exe)

If, gdb.exe, and if that does not exist anywhere, download from here, gdb.exe I just unzip the appropriate directory.
Extracting the destination specified here.

Download: http://ftp.gnu.org/gnu/gdb/
Today 2010.05, gdb-7.1.tar.gz seems to be the latest, download it, unzip use.

Let's make Qt applications.
File (F)] - File / New Project

Project - [Qt4 GUI Application Selected.

Project Name and set the destination path of the project.

If you need Qt library, check here. Because we do not need anything, just are.

Class name, base class, header files, source files, to create a form, and specify the form file.
Here, select the base class QDialog.

This is the confirmation screen.

The project opens automatically created.

Let's build the project.

Let's run debug the project.

Screen appears there is no part of the screen.

Encoding problem with MinGW

MinGW is basically, regardless of character. Conversely speaking, the default behavior, all character codes ASCII (Laten) that are also recognized. If you do not specify anything in particular, character codes within the program will be treated in the source code of the character. This point, VC + + are similar. If you use the Japanese version, SJIS, UNICODE (UTF-16) can be used. Character in the source code is handled internally literal, ShiftJIS Determine what will be a UNICODE.

#include <string.h>
#include <stdio.h>
 
int main ()
{
const char *asample = "ab漢字";
int nsize=(int)strlen(asample);
printf("[%d]%s\n", nsize,asample);
return 1;
}

For example, the above code and saved ShiftJIS UNICODE (UTF-8 BOM in), but try to save the cl command to compile.

C:\vc > cl sample_sjis.cpp
 
C:\vc > cl sample_utf8.cpp

Accept it, DOS prompt, run from.

C:\vc > sample_sjis.exe
[6]ab漢字
 
C:\vc > sample_utf8.exe
[8]ab貍「蟄・

Fine, 06-byte data are seen as 8-byte data. If the UNICODE, the output string UNICODE (UTF-8) is garbled to.

Continues, MinGW Try the same way.

C:\MinGW > g++ -o s_sjis.exe sample_sjis.cpp
 
C:\MinGW > g++ -o s_utf8.exe sample_utf8.cpp
sample_utf8.cpp:1: error: stray '\239' in program
sample_utf8.cpp:1: error: stray '\187' in program
sample_utf8.cpp:1: error: stray '\191' in program
            :
            :
            :
            :
 
C:\MinGW > 

As mentioned above, MinGW does, rather than in the GCC, UNICODE BOM is not to have a properly compiled. Here, UTF-8 BOM files without "sample_utf8n.cpp" Let's create a compilation like.

C:\MinGW > g++ -o s_utf8n.exe sample_utf8n.cpp
 
C:\MinGW > 

Now the time being, VC could be the same. Let each run.

C:\MinGW > s_sjis.exe
[6]ab漢字
 
C:\MinGW > sample_utf8n.exe
[8]ab貍「蟄・

For GCC, the character encoding of input and executable can be specified for each. In, UTF-8 ShiftJIS let the source code to convert the executable file.

C:\MinGW > g++ -o s_utf8_sjis.exe -finput-charset=utf-8 -fexec-charset=CP932 sample_utf8.cpp
 
C:\MinGW > s_utf8_sjis.exe
[6]ab漢字
 
C:\MinGW > 

Like this, UNICODE (UTF-8) far from the source code for Windows could create an application ShiftJIS.

Well, ShiftJIS source code is written in, you can leave it and say, different.
Similarly, the source code may not compile correctly ShiftJIS I need to be specified.

Let ShiftJIS following source code to compile.

#include <string.h>
#include <stdio.h>
 
int main ()
{
const char *asample = "ソ";
int nsize=(int)strlen(asample);
printf("[%d]%s\n", nsize,asample);
return 1;
}

Would be an error like this.
This, GCC character codes are strictly ASCII (laten) is proof that you recognize.

C:\MinGW > g++ -o s2_sjis.exe sample2_sjis.cpp
sample2_sjis.cpp: In function `int main()':
sample2_sjis.cpp:6: error: missing terminating " character
sample2_sjis.cpp:7: error: expected primary-expression before "int"
sample2_sjis.cpp:7: error: expected `,' or `;' before "int"
sample2_sjis.cpp:8: error: `nsize' was not declared in this scope
 
C:\MinGW > 

To compile this source code correctly, you'll work - as specified below.

C:\MinGW > g++ -o s2_sjis.exe -finput-charset=CP932 -fexec-charset=CP932 sample2_sjis.cpp
 
C:\MinGW > s2_sjis.exe
[2]ソ
 
C:\MinGW\3>

Now, ShiftJIS I could compile the source code written in.

Let's Qt Japanese text display applications.

Based on this far, Qt Creator + MinGW try to embed source code in Japanese.
In VC + +, I could write anything without knowing Japanese. However, MinGW, if you write Japanese, you'll need to specify a character encoding where the source code to compile options.

In the above, g + + was written directly to the parameters. Qt Creator allows you to write the project file.

QMAKE_CXXFLAGS += -finput-charset=CP932 -fexec-charset=CP932

Adding to this, ShiftJIS source code written in ShiftJIS you can create a Windows application.
In addition, UTF-8 if the source code, should I as follows.

QMAKE_CXXFLAGS += -finput-charset=UTF-8 -fexec-charset=CP932

The projects in the following settings, you can specify the character encoding of the editor.

Does not display a dialog window where nothing will be displayed directly Qt Japanese let the title application.

Append a line like this: 09 titles to display.

1
2
3
4
5
6
7
8
9
10
#include "dialog.h"
#include "ui_dialog.h"
 
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
	setWindowTitle (  QString::fromLocal8Bit("ソフトウェアのタイトル") );
}

The following screen appears when you build and run it.

GCC and you get used to this feature, Qt will also become easier to make a feature of cross-platform applications.
Absolutely, Windows and are familiar with the author, VC + + and from the convenience of, I think Naa database has a hassle. ^ ^;


Comments

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ