<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1629739459234463496</atom:id><lastBuildDate>Tue, 25 Dec 2012 22:44:57 +0000</lastBuildDate><category>linux</category><category>J2ME</category><category>QString</category><category>pom.xml</category><category>client</category><category>Apache POI</category><category>Rails</category><category>PL/SQL</category><category>Hibernate</category><category>Junit</category><category>QGraphicsView</category><category>Maven2</category><category>distributed applications</category><category>Java 1.5</category><category>pipe</category><category>Java</category><category>JME</category><category>C++</category><category>yaml</category><category>tcp</category><category>socket</category><category>QXMLStreamWriter</category><category>Ruby</category><category>Eclipse Ganymede</category><category>Eclipse</category><category>QGraphicsItem</category><category>Qt</category><category>server</category><category>QGraphicsScene</category><category>Ubuntu</category><category>QDataStream</category><category>Ruby on Rails</category><category>QLibrary</category><category>QVariant</category><category>QDialog</category><category>Commons Net FtpClient</category><category>QDebug</category><category>QTest</category><category>rpcgen utility</category><title>Lifecycle</title><description /><link>http://tufangorel.blogspot.com/</link><managingEditor>noreply@blogger.com (Tufan)</managingEditor><generator>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/QFhJrM" /><feedburner:info uri="blogspot/qfhjrm" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>blogspot/QFhJrM</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-4830507792122514896</guid><pubDate>Sun, 13 Nov 2011 22:56:00 +0000</pubDate><atom:updated>2011-11-14T01:11:56.301+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QLibrary</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Call Symbol From Shared Object File (DLL) with QLibrary</title><description>&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Shared libraries are represented with *.dll and *.so files on windows and unix platforms; respectively. Symbols in a shared object file (*.dll,*.so) are designed to be exported by the library writer. Client imports symbols from shared library.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; In this sample there are two projects in the Qt Creator projects pane which are &lt;b&gt;SharedLib &lt;/b&gt;and &lt;b&gt;SharedLibClient&lt;/b&gt;. SharedLib is a C++ Library project which creates a shared object file (dll) with an exported symbol in it. SharedLibClient is a QT Console Application which calls SharedLib dll at runtime. In order to debug SharedLibClient project successfully, required “SharedLib.dll” file is placed under the debug folder of the SharedLibClient project.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FOMyES6L-MA/TsA_4Y1i5xI/AAAAAAAAAGw/nQRBNJCNuGU/s1600/sharedLibProject.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="272" src="http://3.bp.blogspot.com/-FOMyES6L-MA/TsA_4Y1i5xI/AAAAAAAAAGw/nQRBNJCNuGU/s320/sharedLibProject.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;SharedLib project contains a simple symbol which sums two integers and returns the result. &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;&lt;b&gt;SharedLib.pro&lt;/b&gt; is the project configuration file and contains:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class="Java" name="code"&gt;QT       -= gui
TARGET = SharedLib
TEMPLATE = lib
DEFINES += SHAREDLIB_LIBRARY
SOURCES += Sharedlib.cpp
HEADERS += Sharedlib.h\
        SharedLib_global.h
&lt;/pre&gt;SharedLib_global.h is created by the QT Creator IDE for the new C++ Library project and contains:&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#ifndef SHAREDLIB_GLOBAL_H
#define SHAREDLIB_GLOBAL_H

#include &amp;lt;QtCore&amp;gt;

#if defined(SHAREDLIB_LIBRARY)
#  define SHAREDLIBSHARED_EXPORT Q_DECL_EXPORT
#else
#  define SHAREDLIBSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif

&lt;/pre&gt;Sharedlib.h is the header file and contains implementation details for the Sharedlib.&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#ifndef SHAREDLIB_H
#define SHAREDLIB_H

#include "SharedLib_global.h"

class SHAREDLIBSHARED_EXPORT SharedLib {
public:
    SharedLib();
    int addNumbers(int num1, int num2);
};

#endif
&lt;/pre&gt;Sharedlib.cpp file contains the implementation for the addNumbers function.&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include "Sharedlib.h"

extern "C" __declspec(dllexport) int addNumbers(int no1, int no2)
{
    return no1+no2;
}
&lt;/pre&gt;addNumbers(int,int) symbol is exported as a C function from the SharedLib library. Function is also wrapped in an extern "C" block. If you are building on Windows, the function needs to be explicitly exported from the DLL using the __declspec(dllexport) compiler directive.&lt;br /&gt;
In order to create "SharedLib" project in Qt Creator, create a "Qt Shared Library" project and add only one cpp file into it. Inside this cpp file sign your function that you are willing to export with dllexport macro. Then build the project in debug mode. After building the "SharedLib" project in debug mode by Qt Creator IDE, related dll file is generated under the "SharedLibClient\SharedLibClient-build-desktop" folder of SharedLib project for Windows platform.&lt;br /&gt;
&lt;br /&gt;
In order to create "SharedLibClient" project in Qt Creator, create a simple client "Qt Console Application" that is going to use "addNumbers" function from "SharedLib.dll" library. SharedLibClient project contains simply a main.cpp file. In this main.cpp file QLibrary class of QT framework  is used to load shared library (SharedLib.dll on Windows) at runtime. One of the amazing features of QLibrary is that it provides platform independent access to specific library at run-time. In order to load specific library at run-time, just give the name of the *.dll or *.so file without suffix to QLibrary constructor. In this case only the name of the library without suffix "SharedLib" is going to be enough to load it into memory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SharedLibClient.pro&lt;/b&gt; is the project configuration file and contains :&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;QT       += core
QT       -= gui
TARGET = SharedLibClient
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
&lt;/pre&gt;In main.cpp file, shared library function addNumbers from the SharedLib.dll is called by using the QLibrary resolve function.&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include &amp;lt;QCoreApplication&amp;gt;
#include &amp;lt;QLibrary&amp;gt;
#include &amp;lt;QtDebug&amp;gt;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    int result = 0;
    QLibrary myLib("SharedLib");
    typedef int (*MyPrototype)(int,int);
    MyPrototype myFunction = (MyPrototype) myLib.resolve("addNumbers");
    if( myFunction )
        result = myFunction(3,2);
    if( myFunction == 0 || result == 0 ) {
        qDebug() &amp;lt;&amp;lt; myLib.errorString();
        qDebug() &amp;lt;&amp;lt; "Can not get result from dll!";
        myLib.unload();
        return 0;
    }
    result = result+2;
    qDebug() &amp;lt;&amp;lt; result;
    myLib.unload();
    return a.exec();
}
&lt;/pre&gt;&lt;br /&gt;
After running the SharedLibClient project in debug mode, the result is displayed on the console output.&lt;br /&gt;
&lt;br /&gt;
main function of “SharedLibClient” project accomplishes following steps sequentially :&lt;br /&gt;
- Loads the library by passing the library file name in the QLibrary constructor&lt;br /&gt;
- Declares a function pointer to the symbol&lt;br /&gt;
- Calls the function of the exported library by resolve function of QLibrary&lt;br /&gt;
&lt;br /&gt;
If QLibrary can not load the symbol from library, then  the function pointer will be assigned to 0.&lt;br /&gt;
&lt;br /&gt;
Benefits of Using QLibrary to Load Shared Object (DLL) Files at Run-Time :&lt;br /&gt;
- You do not need to have the header and lib files to compile the application.&lt;br /&gt;
- Just put your dll file that you want to load at run-time next to your executable .&lt;br /&gt;
- Executable can start without having dll next to it because dll is going to be loaded at run-time when it is required.&lt;br /&gt;
- Helps to generate a smaller executable file as a result.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QT" rel="tag"&gt;QT&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QLibrary" rel="tag"&gt;QLibrary&lt;/a&gt;&lt;br /&gt;
&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/E-YGFS-mjbE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/E-YGFS-mjbE/call-symbol-from-shared-object-file-dll.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-FOMyES6L-MA/TsA_4Y1i5xI/AAAAAAAAAGw/nQRBNJCNuGU/s72-c/sharedLibProject.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/11/call-symbol-from-shared-object-file-dll.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8675632502787872143</guid><pubDate>Thu, 20 Oct 2011 18:53:00 +0000</pubDate><atom:updated>2011-10-20T22:04:08.451+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Triple Pointer Operations in C++</title><description>&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;Double pointer can be used to point to two dimensional matrix (pointer-to-pointer). If there are more than one matrices and it is required to keep track of these matrices then an additional extra pointer will be required. At his point triple-pointers can be used to point to list of two dimensional matrices.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;We assume that you have got three different two-dimensional matrices as in the below picture:&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;Triple pointer with size of 3 and pointing to 3 different matrices: &lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-3lJ8Fxus4Sc/TqBqzOS9QPI/AAAAAAAAAGM/HKCkxVv2as0/s1600/triplePointer.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="281" src="http://1.bp.blogspot.com/-3lJ8Fxus4Sc/TqBqzOS9QPI/AAAAAAAAAGM/HKCkxVv2as0/s400/triplePointer.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include &amp;lt;QCoreApplication&amp;gt;
#include &amp;lt;iostream&amp;gt;
using namespace std;

//function prototype
int** initializeMatrix(int** tempMatrix, int row, int column, int matrixCellValue);


int main(int argc, char *argv[])
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; QCoreApplication a(argc, argv);
&amp;nbsp;&amp;nbsp;&amp;nbsp; int size = 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int*** triplePointer;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //Allocate memory for triplePointer
&amp;nbsp;&amp;nbsp;&amp;nbsp; triplePointer = new int**[size];

&amp;nbsp;&amp;nbsp;&amp;nbsp; int rowNum = 4;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int columnNum = 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int** newMatrix = 0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //Assign elements to cell values of each matrix
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;size; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; triplePointer[i] = initializeMatrix(newMatrix,rowNum,columnNum,i);

&amp;nbsp;&amp;nbsp;&amp;nbsp; //Print elements of allocated matrices
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int num = 0; num&amp;lt;size; num++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;rowNum; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int j=0; j&amp;lt;columnNum; j++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;triplePointer[num][i][j];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; "\n";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; "\n";
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; return a.exec();


}

/*
tempMatrix: matrix to allocate
row: number of rows of the matrix
column: number of columns of the matrix
matrixCellValue: value to assign to specified cell of matrix
&amp;nbsp;*/
int** initializeMatrix(int** tempMatrix, int row, int column, int matrixCellValue)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; tempMatrix = new int*[row];
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;row; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempMatrix[i] = new int[column];
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;row; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int j=0; j&amp;lt;column; j++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tempMatrix[i][j] = matrixCellValue;

&amp;nbsp;&amp;nbsp;&amp;nbsp; return tempMatrix;
}

&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
Sample c++ console application built with qt-creator on ubuntu and the console-output is 3 different 2x2 matrices displayed. Same output is produced when built with MSVS2008 on winXP.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-QtGoE-o9ETk/TqBv0Ez0m3I/AAAAAAAAAGU/Rypa2xXnH_A/s1600/triplePointerConsoleResult.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="211" src="http://3.bp.blogspot.com/-QtGoE-o9ETk/TqBv0Ez0m3I/AAAAAAAAAGU/Rypa2xXnH_A/s400/triplePointerConsoleResult.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Pointers" rel="tag"&gt;Pointers&lt;/a&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/MOpfNHgFw_0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/MOpfNHgFw_0/triple-pointer-operations-in-c.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-3lJ8Fxus4Sc/TqBqzOS9QPI/AAAAAAAAAGM/HKCkxVv2as0/s72-c/triplePointer.PNG" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/10/triple-pointer-operations-in-c.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-4700532589010480678</guid><pubDate>Wed, 12 Oct 2011 20:24:00 +0000</pubDate><atom:updated>2011-10-26T00:34:57.476+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Double Pointer Operations in C++</title><description>When initialized properly double pointers can be used as a 2 dimensional matrix. Sample qt-console application shows a way to &lt;b&gt;allocate&lt;/b&gt;, &lt;b&gt;initialize&lt;/b&gt; and &lt;b&gt;deallocate&lt;/b&gt; a &lt;b&gt;double pointer &lt;/b&gt;in&lt;b&gt; C++&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Following diagrams help me to remember the subject of dynamically allocating multi-dimensional arrays in C++.&lt;span lang="EN-US"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span lang="EN-US"&gt;Pointer-to-integer (simple integer array) declaration and representation: Can be considered as an array of integers.&lt;/span&gt;&lt;br /&gt;
&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;int* ptrToInt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HGA6POey2Vw/TqcpMFCViZI/AAAAAAAAAGc/Dfu7y9UqvGg/s1600/pointeToInt.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-HGA6POey2Vw/TqcpMFCViZI/AAAAAAAAAGc/Dfu7y9UqvGg/s1600/pointeToInt.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;Pointer-to-pointer-to-integer (multi-dimensional matrix) declaration and representation: Can be considered as array of arrays of integers.&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span lang="EN-US"&gt;int** ptrToPtrToInt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Thp1XDfAYVU/TqcqLxj69zI/AAAAAAAAAGk/vWispTsNePE/s1600/pointerToPtrToInt.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="188" src="http://3.bp.blogspot.com/-Thp1XDfAYVU/TqcqLxj69zI/AAAAAAAAAGk/vWispTsNePE/s320/pointerToPtrToInt.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;/div&gt;&lt;span lang="EN-US"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include &amp;lt;QCoreApplication&amp;gt;
#include &amp;lt;iostream&amp;gt;

using namespace std;

int main(int argc, char *argv[])
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; QCoreApplication a(argc, argv);

&amp;nbsp;&amp;nbsp;&amp;nbsp; int** myRectRegion;

&amp;nbsp;&amp;nbsp;&amp;nbsp; int numRows = 4;
&amp;nbsp;&amp;nbsp;&amp;nbsp; int numCols = 3;

&amp;nbsp;&amp;nbsp;&amp;nbsp; //allocate double pointer
&amp;nbsp;&amp;nbsp;&amp;nbsp; myRectRegion = new int* [numRows];
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;numRows;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myRectRegion[i] = new int[numCols];


&amp;nbsp;&amp;nbsp;&amp;nbsp; //initialize double pointer
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;numRows; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int j=0;j&amp;lt;numCols;j++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myRectRegion[i][j] = 1;


&amp;nbsp;&amp;nbsp;&amp;nbsp; //print double pointer elements
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;numRows; i++){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int j=0; j&amp;lt;numCols; j++){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; myRectRegion[i][j];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; "\n";
&amp;nbsp;&amp;nbsp;&amp;nbsp; }


&amp;nbsp;&amp;nbsp;&amp;nbsp; //free deallocate double pointer
&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;numRows;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete[] myRectRegion[i];
&amp;nbsp;&amp;nbsp;&amp;nbsp; delete[] myRectRegion;

&amp;nbsp;&amp;nbsp;&amp;nbsp; return a.exec();
}
&lt;/pre&gt;&lt;br /&gt;
When the application is run, a 4X3 matrix is displayed in the terminal window.&lt;br /&gt;
&lt;br /&gt;
There is also a helpful tutorial about dynamic allocation of multi-dimensional arrays in C at :&amp;nbsp;&lt;a href="http://c-faq.com/%7Escs/cclass/int/sx9b.html"&gt;http://c-faq.com/~scs/cclass/int/sx9b.html&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/FGD9j7MkYQA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/FGD9j7MkYQA/double-pointer-operations-in-c.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-HGA6POey2Vw/TqcpMFCViZI/AAAAAAAAAGc/Dfu7y9UqvGg/s72-c/pointeToInt.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/10/double-pointer-operations-in-c.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-1147255615002263115</guid><pubDate>Tue, 23 Aug 2011 20:28:00 +0000</pubDate><atom:updated>2011-10-20T22:05:04.851+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">QGraphicsScene</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Draw Grid on QGraphicsScene</title><description>Derived QGraphisScene class enables child class to reimplement drawBackground() function of the parent class. By reimplementing drawBackground() function, child class draws the background of the scene using painter.  &lt;br /&gt;
Sample project started as a QT Gui Application and contains main.cpp, CustomQGraphicsScene.h, CustomQGraphicsScene.cpp, Dialog.h and Dialog.cpp files. &lt;br /&gt;
Project Directory Structure in &lt;span style="font-weight: bold;"&gt;Qt Creator IDE&lt;/span&gt; : &lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-ZEgLH6WYu7A/TlQPQhZv6vI/AAAAAAAAAFw/ixikVL6iCd4/s1600/project_file.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5644153009520765682" src="http://4.bp.blogspot.com/-ZEgLH6WYu7A/TlQPQhZv6vI/AAAAAAAAAFw/ixikVL6iCd4/s320/project_file.png" style="cursor: pointer; display: block; height: 176px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
DrawGridOnQGraphicsScene.pro is the project configuration file and contains: &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;QT       += core gui
TARGET = DrawGridOnQGraphicsScene
TEMPLATE = app
SOURCES += main.cpp \
           Dialog.cpp \
           CustomQGraphicsScene.cpp
HEADERS  += Dialog.h \
            CustomQGraphicsScene.h
&lt;/pre&gt;&lt;br /&gt;
main.cpp file contains the &lt;span style="font-weight: bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it. &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include &amp;lt;QApplication&amp;gt;
#include "Dialog.h"

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   Dialog w;
   w.show();
   return a.exec();
}

&lt;/pre&gt;&lt;br /&gt;
Dialog.h is derived from QDialog class which contains QGraphicsView in it. &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#ifndef DIALOG_H
#define DIALOG_H
#include &amp;lt;QDialog&amp;gt;

class CustomQGraphicsScene;
class QGraphicsView;
class QVBoxLayout;

class Dialog : public QDialog
{
   Q_OBJECT
public:
   Dialog(QWidget *parent = 0);
   ~Dialog();
private:
   CustomQGraphicsScene* scene;
   QGraphicsView* view;
   QVBoxLayout* layout;
};

#endif // DIALOG_H
&lt;/pre&gt;&lt;br /&gt;
Dialog.cpp contains implementation details for derived QDialog class. &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include "Dialog.h"
#include "CustomQGraphicsScene.h"
#include &amp;lt;QVBoxLayout&amp;gt;
#include &amp;lt;QGraphicsView&amp;gt;

Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
   scene = new CustomQGraphicsScene(this);
   view = new QGraphicsView(scene,this);
   layout = new QVBoxLayout(this);
   layout-&amp;gt;addWidget(view);
   setLayout(layout);
   resize(270,200);
}

Dialog::~Dialog()
{
   delete scene;
   delete view;
}

&lt;/pre&gt;&lt;br /&gt;
Custom QDialog creates an instance of derived QGraphicsScene and displays in a QGraphicsView. &lt;br /&gt;
CustomQGraphicsScene.h is derived from QGraphicsScene in which drawBackground() function is reimplemented to draw grid on it. &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#ifndef CUSTOMQGRAPHICSSCENE_H
#define CUSTOMQGRAPHICSSCENE_H
#include &amp;lt;QGraphicsScene&amp;gt;

class CustomQGraphicsScene : public QGraphicsScene
{
public:
   CustomQGraphicsScene(QObject *parent);

protected:
   void drawBackground(QPainter * painter, const QRectF &amp;amp; rect );
};

#endif // CUSTOMQGRAPHICSSCENE_H
&lt;/pre&gt;&lt;br /&gt;
CustomQGraphicsScene.cpp contains implementation details for derived QGraphicsScene class. &lt;br /&gt;
&lt;pre class="Java" name="code"&gt;#include "CustomQGraphicsScene.h"
#include &amp;lt;QPainter&amp;gt;

static const int GRID_STEP = 30;

inline qreal round(qreal val, int step) {
   int tmp = int(val) + step /2;
   tmp -= tmp % step;
   return qreal(tmp);
}

CustomQGraphicsScene::CustomQGraphicsScene(QObject *parent ) : QGraphicsScene(parent)
{}

void CustomQGraphicsScene::drawBackground(QPainter *painter, const QRectF &amp;amp;rect)
{
   int step = GRID_STEP;
   painter-&amp;gt;setPen(QPen(QColor(200, 200, 255, 125)));
   // draw horizontal grid
   qreal start = round(rect.top(), step);
   if (start &amp;gt; rect.top()) {
      start -= step;
   }
   for (qreal y = start - step; y &amp;lt; rect.bottom(); ) {
      y += step;
      painter-&amp;gt;drawLine(rect.left(), y, rect.right(), y);
   }
   // now draw vertical grid
   start = round(rect.left(), step);
   if (start &amp;gt; rect.left()) {
      start -= step;
   }
   for (qreal x = start - step; x &amp;lt; rect.right(); ) {
      x += step;
      painter-&amp;gt;drawLine(x, rect.top(), x, rect.bottom());
   }
}

&lt;/pre&gt;&lt;br /&gt;
Drawing grid process is divided into two substeps such as drawing vertical and drawing horizontal lines. Derived QGraphicsScene instance in which drawBackground() function is reimplemented looks like following screenShot : &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/--Ulk6LkXg28/TlQTeARWwlI/AAAAAAAAAF4/i8go2NAHpb8/s1600/drawGridOnGraphicsScene.png"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5644157639191872082" src="http://1.bp.blogspot.com/--Ulk6LkXg28/TlQTeARWwlI/AAAAAAAAAF4/i8go2NAHpb8/s320/drawGridOnGraphicsScene.png" style="cursor: pointer; display: block; height: 214px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Qt" rel="tag"&gt;Qt&lt;/a&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/n91RHgK3yGk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/n91RHgK3yGk/draw-grid-on-qgraphicsscene.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-ZEgLH6WYu7A/TlQPQhZv6vI/AAAAAAAAAFw/ixikVL6iCd4/s72-c/project_file.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/08/draw-grid-on-qgraphicsscene.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-7666322422462402393</guid><pubDate>Wed, 03 Aug 2011 20:31:00 +0000</pubDate><atom:updated>2011-08-04T00:05:48.083+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGraphicsItem</category><category domain="http://www.blogger.com/atom/ns#">QXMLStreamWriter</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><category domain="http://www.blogger.com/atom/ns#">QDialog</category><title>Save QGraphicsScene to XML File By Using QXmlStreamWriter</title><description>QGraphicsItems that are residing in a QGraphicsScene can be saved to XML file by using QXMLStreamWriter class.&lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, SaveQGraphicsSceneToXML.h, SaveQGraphicsSceneToXML.cpp, MyGraphicsItem.h and MyGraphicsItem.cpp files.&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-83qDC93KkR4/TjmxYSpZsNI/AAAAAAAAAFo/tz2ApBfzxNE/s1600/project.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 298px; height: 178px;" src="http://2.bp.blogspot.com/-83qDC93KkR4/TjmxYSpZsNI/AAAAAAAAAFo/tz2ApBfzxNE/s320/project.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5636731439511351506" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;SaveQGraphicsSceneToXML.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += core gui&lt;br /&gt;TARGET = SaveQGraphicsSceneToXML&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp\&lt;br /&gt;        SaveQGraphicsSceneToXML.cpp\&lt;br /&gt;        MyGraphicsItem.cpp&lt;br /&gt;HEADERS  += SaveQGraphicsSceneToXML.h\&lt;br /&gt;            MyGraphicsItem.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "SaveQGraphicsSceneToXML.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    Dialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;MyGraphicsItem is a derived custom QGraphicsItem class that implements boundingRect() and paint() functions of the parent. MyGraphicsItem is a rectangular derived QGraphicsItem and added to the QGraphicsScene.&lt;br /&gt;MyGraphicsItem.h file contains custom QGraphicsItem class declaration.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef MYGRAPHICSITEM_H&lt;br /&gt;#define MYGRAPHICSITEM_H&lt;br /&gt;#include &amp;lt;QGraphicsItem&amp;gt;&lt;br /&gt;class MyGraphicsItem : public QGraphicsItem&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    MyGraphicsItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);&lt;br /&gt;    ~MyGraphicsItem();&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;    QRectF boundingRect() const;&lt;br /&gt;&lt;br /&gt;    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;               QWidget *widget);&lt;br /&gt;};&lt;br /&gt;#endif // MYGRAPHICSITEM_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;MyGraphicsItem.cpp file contains implementation details for custom QGraphicsItem class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;MyGraphicsItem::MyGraphicsItem(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent,scene)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;MyGraphicsItem::~MyGraphicsItem(){}&lt;br /&gt;&lt;br /&gt;QRectF MyGraphicsItem::boundingRect() const&lt;br /&gt;{&lt;br /&gt;    qreal penWidth = 1;&lt;br /&gt;    return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,&lt;br /&gt;                  20 + penWidth, 20 + penWidth);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;           QWidget *widget)&lt;br /&gt;{&lt;br /&gt;    Q_UNUSED(widget)&lt;br /&gt;    Q_UNUSED(option)&lt;br /&gt;&lt;br /&gt;    QPen pen;&lt;br /&gt;    pen.setWidthF(2);&lt;br /&gt;    pen.setStyle(Qt::DashLine);&lt;br /&gt;    painter-&gt;setPen(pen);&lt;br /&gt;    painter-&gt;setBrush(QBrush(QColor(50,120,80)));&lt;br /&gt;    painter-&gt;drawRoundedRect(boundingRect(), 25, 25, Qt::RelativeSize);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;SaveQGraphicsSceneToXML.h is derived from QDialog class which contains QGraphicsView in it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef SAVEQGRAPHICSSCENETOXML_H&lt;br /&gt;#define SAVEQGRAPHICSSCENETOXML_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;&lt;br /&gt;class QGraphicsScene;&lt;br /&gt;class MyGraphicsItem;&lt;br /&gt;class QGraphicsView;&lt;br /&gt;class QVBoxLayout;&lt;br /&gt;&lt;br /&gt;class Dialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    Dialog(QWidget *parent = 0);&lt;br /&gt;    ~Dialog();&lt;br /&gt;&lt;br /&gt;public slots:&lt;br /&gt;    void sl_saveSceneToXML();&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;    QGraphicsScene* scene;&lt;br /&gt;    MyGraphicsItem* item;&lt;br /&gt;    QGraphicsView* view;&lt;br /&gt;    QVBoxLayout* layout;&lt;br /&gt;    QPushButton* btnSaveToXML;&lt;br /&gt;};&lt;br /&gt;#endif // SAVEQGRAPHICSSCENETOXML_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;SaveQGraphicsSceneToXML.cpp contains implementation details for derived QDialog class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "SaveQGraphicsSceneToXML.h"&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;&lt;br /&gt;#include &amp;lt;QGraphicsScene&amp;gt;&lt;br /&gt;#include &amp;lt;QGraphicsView&amp;gt;&lt;br /&gt;#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QFile&amp;gt;&lt;br /&gt;#include &amp;lt;QList&amp;gt;&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;#include &amp;lt;QXmlStreamWriter&amp;gt;&lt;br /&gt;#include &amp;lt;QDir&amp;gt;&lt;br /&gt;&lt;br /&gt;Dialog::Dialog(QWidget *parent)&lt;br /&gt;    : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    scene = new QGraphicsScene(this);&lt;br /&gt;    item = new MyGraphicsItem();&lt;br /&gt;    item-&gt;setPos(34,35);&lt;br /&gt;    scene-&gt;addItem(item);&lt;br /&gt;    view = new QGraphicsView(scene,this);&lt;br /&gt;    layout = new QVBoxLayout(this);&lt;br /&gt;    layout-&gt;addWidget(view);&lt;br /&gt;    btnSaveToXML = new QPushButton("Save Scene To XML");&lt;br /&gt;    connect(btnSaveToXML, SIGNAL(clicked()), this, SLOT(sl_saveSceneToXML()));&lt;br /&gt;    layout-&gt;addWidget(btnSaveToXML);&lt;br /&gt;    setLayout(layout);&lt;br /&gt;    resize(270,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Dialog::~Dialog()&lt;br /&gt;{&lt;br /&gt;    delete btnSaveToXML;&lt;br /&gt;    delete item;&lt;br /&gt;    delete scene;&lt;br /&gt;    delete view;&lt;br /&gt;    delete layout;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Dialog::sl_saveSceneToXML()&lt;br /&gt;{&lt;br /&gt;    QString fileName(QDir::currentPath().append("//sceneData.xml"));&lt;br /&gt;    QFile file(fileName);&lt;br /&gt;    if (!file.open(QIODevice::WriteOnly))&lt;br /&gt;    {&lt;br /&gt;            return;&lt;br /&gt;    }&lt;br /&gt;    QXmlStreamWriter xmlWriter(&amp;file);&lt;br /&gt;    xmlWriter.setAutoFormatting(true);&lt;br /&gt;    xmlWriter.writeStartDocument();&lt;br /&gt;    xmlWriter.writeStartElement("SceneData");&lt;br /&gt;    xmlWriter.writeAttribute("version", "v1.0");&lt;br /&gt;    xmlWriter.writeStartElement("GraphicsItemList");&lt;br /&gt;    foreach( QGraphicsItem* item, scene-&gt;items())&lt;br /&gt;    {&lt;br /&gt;        if( item-&gt;type() == MyGraphicsItem::Type )&lt;br /&gt;        {&lt;br /&gt;            MyGraphicsItem* myItem = (MyGraphicsItem*)item;&lt;br /&gt;            xmlWriter.writeStartElement("MyGraphicsItem");&lt;br /&gt;            xmlWriter.writeAttribute("xCoord", QString::number(myItem-&gt;x()));&lt;br /&gt;            xmlWriter.writeAttribute("yCoord", QString::number(myItem-&gt;y()));&lt;br /&gt;            xmlWriter.writeEndElement();  //end of MyGraphicsItem&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    xmlWriter.writeEndElement();   //end of GraphicsItemList&lt;br /&gt;    xmlWriter.writeEndElement();   //end of SceneData&lt;br /&gt;    QMessageBox::warning(this,"Success","Saved Scene Data to XML File");&lt;br /&gt;    close();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;QGraphicsScene contains custom QGraphicsItem in it. Derived QGraphicsItem position is set and then added onto the QGraphicsScene. Different QGraphicsItems can be added onto the QGraphicsScene, too. &lt;br /&gt;&lt;br /&gt;btnSaveToXML QPushButton is connected to sl_saveSceneToXML slot of current Dialog instance. By clicking on the QPushButton instance which has a text property set to "Save Scene To XML" sl_saveSceneToXML slot is called.&lt;br /&gt;&lt;br /&gt;sl_saveSceneToXML slot saves the content of QGraphicsScene into the sceneData.xml file. QxmlStreamWriter is used to write data into the opened file. &lt;br /&gt;&lt;br /&gt;xmlWriter.writeStartDocument(); line writes a document which starts with XML version number "1.0" and also writes the encoding "UTF-8" information.&lt;br /&gt;&lt;br /&gt;xmlWriter.writeStartElement("SceneData"); line writes the start element with “SceneData”.&lt;br /&gt;&lt;br /&gt;xmlWriter.writeAttribute("version", "v1.0"); line adds “version” attribute with “v1.0” value to  “SceneData” element.&lt;br /&gt;&lt;br /&gt;xmlWriter.writeStartElement("GraphicsItemList"); line writes "GraphicsItemList" under “SceneData” element.&lt;br /&gt;&lt;br /&gt;Foreach custom QGraphicsItem instance that is residing in the QGraphicsScene a new element is inserted into the xml file with writeStartElement("MyGraphicsItem") function of QXmlStreamWriter. Previously setted xCoord and yCoord attributes of custom QGraphicsItem are written into the xml file with writeAttribute("yCoord", Qstring::number(myItem-&gt;y())); function of QxmlStreamWriter.&lt;br /&gt;Foreach writeStartElement() function, corresponding writeEndElement() function is called to close the previous start element. Each QGraphicsItem instance is identified by its item-&gt;type() and written into the XML file.&lt;br /&gt;&lt;br /&gt;“GraphicsItemList” and “SceneData” elements are closed by calling xmlWriter.writeEndElement(); .&lt;br /&gt;&lt;br /&gt;Saved XML file content is :&lt;br /&gt;&lt;br /&gt;&lt;pre class="XML" name="code"&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;br /&gt;&lt;SceneData version="v1.0"&gt; &lt;br /&gt;    &lt;GraphicsItemList&gt; &lt;br /&gt;        &lt;MyGraphicsItem xCoord="34" yCoord="35"/&gt; &lt;br /&gt;    &lt;/GraphicsItemList&gt; &lt;br /&gt;&lt;/SceneData&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QDialog" rel="tag"&gt;QDialog&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QGraphicsItem" rel="tag"&gt;QGraphicsItem&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Qt" rel="tag"&gt;Qt&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QXMLStreamWriter" rel="tag"&gt;QXMLStreamWriter&lt;/a&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/FrJDKV-IwRE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/FrJDKV-IwRE/save-qgraphicsscene-to-xml-file-by.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-83qDC93KkR4/TjmxYSpZsNI/AAAAAAAAAFo/tz2ApBfzxNE/s72-c/project.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/08/save-qgraphicsscene-to-xml-file-by.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-5296733880472365531</guid><pubDate>Tue, 02 Aug 2011 16:41:00 +0000</pubDate><atom:updated>2011-08-02T20:04:01.909+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGraphicsView</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">QGraphicsScene</category><category domain="http://www.blogger.com/atom/ns#">C++</category><category domain="http://www.blogger.com/atom/ns#">QDialog</category><title>Save Screenshot of QGraphicsScene</title><description>In order to display items that are residing in QGraphicsScene, QGraphicsView is used. In the sample application Custom QDialog contains a QGraphicsView with a QGraphicsScene inside it. &lt;br /&gt;&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-J2vz9-12sX4/TjgpLEjRw-I/AAAAAAAAAFQ/rkrHnnlViso/s1600/directoryStructure.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 296px; height: 132px;" src="http://4.bp.blogspot.com/-J2vz9-12sX4/TjgpLEjRw-I/AAAAAAAAAFQ/rkrHnnlViso/s320/directoryStructure.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5636300203831182306" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;SaveQGraphicsSceneAsImage.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += core gui&lt;br /&gt;TARGET = SaveQGraphicsSceneAsImage&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp\&lt;br /&gt;        Dialog.cpp&lt;br /&gt;HEADERS  += Dialog.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "Dialog.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    Dialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Dialog.h file contains custom QDialog interface.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef DIALOG_H&lt;br /&gt;#define DIALOG_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;class QGraphicsScene;&lt;br /&gt;class QGraphicsView;&lt;br /&gt;class QVBoxLayout;&lt;br /&gt;&lt;br /&gt;class Dialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    Dialog(QWidget *parent = 0);&lt;br /&gt;    ~Dialog();&lt;br /&gt;&lt;br /&gt;public slots:&lt;br /&gt;    void sl_saveSceneAsImage();&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;    QGraphicsScene* scene;&lt;br /&gt;    QGraphicsView* view;&lt;br /&gt;    QVBoxLayout* layout;&lt;br /&gt;    QPushButton* btnSaveScene;&lt;br /&gt;};&lt;br /&gt;#endif // DIALOG_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Dialog.cpp file contains implementation details for the custom QDialog. &lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "Dialog.h"&lt;br /&gt;&lt;br /&gt;#include &amp;lt;QGraphicsView&amp;gt;&lt;br /&gt;#include &amp;lt;QGraphicsScene&amp;gt;&lt;br /&gt;#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QString&amp;gt;&lt;br /&gt;#include &amp;lt;QFileDialog&amp;gt;&lt;br /&gt;#include &amp;lt;QPixmap&amp;gt;&lt;br /&gt;&lt;br /&gt;Dialog::Dialog(QWidget *parent)&lt;br /&gt;    : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    scene = new QGraphicsScene(this);&lt;br /&gt;    scene-&gt;addEllipse(22,3,12,13,QPen(QColor("red")));&lt;br /&gt;    scene-&gt;addLine(1,2,8,9,QPen("blue"));&lt;br /&gt;    scene-&gt;addRect(12,12,6,7,QPen("green"));&lt;br /&gt;    view = new QGraphicsView(scene,this);&lt;br /&gt;    layout = new QVBoxLayout(this);&lt;br /&gt;    btnSaveScene = new QPushButton("Take Scene SnapShot");&lt;br /&gt;    connect(btnSaveScene, SIGNAL(clicked()), this, SLOT(sl_saveSceneAsImage()));&lt;br /&gt;    layout-&gt;addWidget(view);&lt;br /&gt;    layout-&gt;addWidget(btnSaveScene);&lt;br /&gt;    setLayout(layout);&lt;br /&gt;    resize(270,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Dialog::~Dialog()&lt;br /&gt;{&lt;br /&gt;    delete btnSaveScene;&lt;br /&gt;    delete scene;&lt;br /&gt;    delete view;&lt;br /&gt;    delete layout;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Dialog::sl_saveSceneAsImage()&lt;br /&gt;{&lt;br /&gt;    QString fileName = QFileDialog::getSaveFileName(this, "Save Scene", "", "Image (*.png)");&lt;br /&gt;    QPixmap pixMap = QPixmap::grabWidget(view);&lt;br /&gt;    pixMap.save(fileName);&lt;br /&gt;    close();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;QGraphicsScene content can be saved as a png image file. Sample QGraphicsScene contains items of type line,rectangle and ellipse. Taken snapshot displays all these items inside of saved snapshot.&lt;br /&gt;&lt;br /&gt;sl_saveSceneAsImage() slot of custom QDialog uses Qpixmap::grabWidget function to create a pixmap and paints the QGraphicsView inside it. Because all the child items are also painted in then QGraphicsScene becomes painted inside snapshot, too.&lt;br /&gt;&lt;br /&gt;As a result Qpixmap instance is saved to specified location with :&lt;br /&gt;pixMap.save(fileName);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sample QGraphicsScene content :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-oBXuLG3FD9s/TjgsTTnN3JI/AAAAAAAAAFY/ld0eJ3zjFr4/s1600/scene.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 270px; height: 222px;" src="http://1.bp.blogspot.com/-oBXuLG3FD9s/TjgsTTnN3JI/AAAAAAAAAFY/ld0eJ3zjFr4/s320/scene.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5636303643848072338" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Saved QGraphicsScene Snapshot :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-l0edFqIZejY/TjgsmBuxUbI/AAAAAAAAAFg/v7svXwTA4j4/s1600/snapShot.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 248px; height: 143px;" src="http://4.bp.blogspot.com/-l0edFqIZejY/TjgsmBuxUbI/AAAAAAAAAFg/v7svXwTA4j4/s320/snapShot.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5636303965465432498" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/Qt" rel="tag"&gt;Qt&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QGraphicsScene" rel="tag"&gt;QGraphicsScene&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QGraphicsView" rel="tag"&gt;QGraphicsView&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QDialog" rel="tag"&gt;QDialog&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/I3ZNsHTusgI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/I3ZNsHTusgI/save-screenshot-of-qgraphicsscene.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-J2vz9-12sX4/TjgpLEjRw-I/AAAAAAAAAFQ/rkrHnnlViso/s72-c/directoryStructure.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/08/save-screenshot-of-qgraphicsscene.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8022658266061528237</guid><pubDate>Thu, 28 Jul 2011 20:13:00 +0000</pubDate><atom:updated>2011-07-28T23:37:50.973+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QTest</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Redirect QTest Output To Log File</title><description>QtTest classes are created by subclassing QObject class and adding private slots into derived QObject class. Every private slot is treated as a testfunction and executed by QTest::qExec() function.&lt;br /&gt;Sample project started as a QT Console Application and contains main.cpp, TestString.h and TestString.cpp files. &lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-5SVtYfgVPvA/TjHEskShDZI/AAAAAAAAAEg/-_WS_hl0abU/s1600/qtestConsole.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 316px; height: 132px;" src="http://3.bp.blogspot.com/-5SVtYfgVPvA/TjHEskShDZI/AAAAAAAAAEg/-_WS_hl0abU/s320/qtestConsole.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5634500878751829394" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;LogQTestOutputToFile.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += testlib core&lt;br /&gt;TARGET = LogQTestOutputToFile&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp \&lt;br /&gt;    TestString.cpp&lt;br /&gt;HEADERS  += TestString.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;QT       += testlib&lt;br /&gt;&lt;br /&gt;line which is used to include testlib dependencies into project.&lt;br /&gt;&lt;br /&gt;TestString.h file contains private slots which are aimed to test mainly toUpper() behavior of String class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;QtTest/QtTest&amp;gt;&lt;br /&gt;#include &amp;lt;QString&amp;gt;&lt;br /&gt;#include &amp;lt;QObject&amp;gt;&lt;br /&gt;&lt;br /&gt;class TestString: public QObject&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;private slots:&lt;br /&gt;    void initTestCase();&lt;br /&gt;    void toUpper();&lt;br /&gt;    void cleanupTestCase();&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;initTestCase() and cleanupTestCase() private slots are executed by the testing framework and used to initialize and release resources; respectively.&lt;br /&gt;&lt;br /&gt;TestString.cpp file contains implementation details for the private slots declared in TestString.h file. &lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "TestString.h"&lt;br /&gt;&lt;br /&gt;void TestString::initTestCase()&lt;br /&gt;{&lt;br /&gt;    qDebug("called before everything else, initialize your resources");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void TestString::toUpper()&lt;br /&gt;{&lt;br /&gt;    QString str = "Hello";&lt;br /&gt;    QCOMPARE(str.toUpper(), QString("HELLO"));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void TestString::cleanupTestCase()&lt;br /&gt;{&lt;br /&gt;    qDebug("called after toUpper(), release allocated resources here");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Because this a QT Console Application, main.cpp file contains only main() function which calls QTest::qExec(&amp;testString, testCmd) function to execute testfunctions in the specified test object.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;#include &amp;lt;QDir&amp;gt;&lt;br /&gt;#include "TestString.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    QStringList testCmd;&lt;br /&gt;    QDir qtestLogDir;&lt;br /&gt;    qtestLogDir.mkdir("UnitTest_Results");&lt;br /&gt;    testCmd&lt;&lt;" "&lt;&lt;"-o"&lt;&lt;"UnitTest_Results/QTestString_log.txt";&lt;br /&gt;    TestString testString;&lt;br /&gt;    QTest::qExec(&amp;testString, testCmd);&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When you run the application, test execution output is displayed at QT Creator Application Output Window. In order to redirect testfunction output to specified log file; output directory and log file name information are passed as argument to QTest::qExec(&amp;testString, testCmd) function. &lt;br /&gt;&lt;br /&gt;testCmd&lt;&lt;" "&lt;&lt;"-o"&lt;&lt;"UnitTest_Results/QTestString_log.txt"; &lt;br /&gt;&lt;br /&gt;command line argument redirects output to UnitTest_Results/QTestString_log.txt file.&lt;br /&gt;&lt;br /&gt;QTestString_log.txt file can be found under LogQTestOutputToFile/UnitTest_Results folder.&lt;br /&gt;&lt;br /&gt;&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/Qt" rel="tag"&gt;Qt&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/C++" rel="tag"&gt;C++&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/QTest" rel="tag"&gt;QTest&lt;/a&gt;&lt;/span&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/j9oiS-oyles" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/j9oiS-oyles/redirect-qtest-output-to-log-file.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-5SVtYfgVPvA/TjHEskShDZI/AAAAAAAAAEg/-_WS_hl0abU/s72-c/qtestConsole.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/07/redirect-qtest-output-to-log-file.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-6807358586161058252</guid><pubDate>Wed, 27 Jul 2011 19:38:00 +0000</pubDate><atom:updated>2011-07-27T23:33:10.051+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QDataStream</category><category domain="http://www.blogger.com/atom/ns#">QGraphicsItem</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">QGraphicsScene</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Load QGraphicsScene From QDataStream</title><description>Qt allows you to read binary data from files into QDataStream. In this sample serialized QGprahicsItem is created on the QGraphicsScene by reading related data from a text file. &lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, LoadSceneFromQDataStream.h, LoadSceneFromQDataStream.cpp, MyGraphicsItem.h and MyGraphicsItem.cpp files.&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-NdS9r5yBboU/TjBt3EC8q_I/AAAAAAAAAEM/fQakw3lMt_0/s1600/loadScene.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 169px;" src="http://3.bp.blogspot.com/-NdS9r5yBboU/TjBt3EC8q_I/AAAAAAAAAEM/fQakw3lMt_0/s320/loadScene.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5634123926586829810" /&gt;&lt;/a&gt;&lt;br /&gt;LoadSceneFromQDataStream.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += core gui&lt;br /&gt;TARGET = LoadSceneFromQDataStream&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp\&lt;br /&gt;        LoadSceneFromQDataStream.cpp \&lt;br /&gt;    MyGraphicsItem.cpp&lt;br /&gt;HEADERS  += LoadSceneFromQDataStream.h \&lt;br /&gt;    MyGraphicsItem.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "LoadSceneFromQDataStream.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    Dialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;LoadSceneFromQDataStream.h file contains custom QDialog which displays content of binary file in a QGraphicsScene instance.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef LOADSCENEFROMQDATASTREAM_H&lt;br /&gt;#define LOADSCENEFROMQDATASTREAM_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;&lt;br /&gt;class QGraphicsScene;&lt;br /&gt;class QGraphicsView;&lt;br /&gt;class QVBoxLayout;&lt;br /&gt;&lt;br /&gt;class Dialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    Dialog(QWidget *parent = 0);&lt;br /&gt;    ~Dialog();&lt;br /&gt;&lt;br /&gt;public slots:&lt;br /&gt;    void sl_loadSceneFromFile();&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;    QGraphicsScene* scene;&lt;br /&gt;    QGraphicsView* view;&lt;br /&gt;    QVBoxLayout* layout;&lt;br /&gt;    QPushButton* btnLoad;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif // LOADSCENEFROMQDATASTREAM_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;LoadSceneFromQDataStream.cpp file contains implementation details for the custom QDialog. &lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "LoadSceneFromQDataStream.h"&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;&lt;br /&gt;#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QGraphicsView&amp;gt;&lt;br /&gt;#include &amp;lt;QFile&amp;gt;&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;#include &amp;lt;QDir&amp;gt;&lt;br /&gt;&lt;br /&gt;Dialog::Dialog(QWidget *parent)&lt;br /&gt;    : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    scene = new QGraphicsScene(this);&lt;br /&gt;    view = new QGraphicsView(scene,this);&lt;br /&gt;    layout = new QVBoxLayout(this);&lt;br /&gt;    layout-&gt;addWidget(view);&lt;br /&gt;    btnLoad = new QPushButton("Load Scene From File");&lt;br /&gt;    connect(btnLoad, SIGNAL(clicked()), this, SLOT(sl_loadSceneFromFile()));&lt;br /&gt;    layout-&gt;addWidget(btnLoad);&lt;br /&gt;    setLayout(layout);&lt;br /&gt;    resize(270,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Dialog::~Dialog()&lt;br /&gt;{&lt;br /&gt;    delete btnLoad;&lt;br /&gt;    delete layout;&lt;br /&gt;    delete scene;&lt;br /&gt;    delete view;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Dialog::sl_loadSceneFromFile()&lt;br /&gt;{&lt;br /&gt;    QString fileName(QDir::currentPath().append("/sceneData.txt"));&lt;br /&gt;    QFile file(fileName);&lt;br /&gt;    if (!file.open(QIODevice::ReadOnly))&lt;br /&gt;    {&lt;br /&gt;            return;&lt;br /&gt;    }&lt;br /&gt;    QDataStream in(&amp;file);&lt;br /&gt;    int itemListSize;&lt;br /&gt;    in &gt;&gt; itemListSize;&lt;br /&gt;    for( int i = 0; i&lt; itemListSize; i++ )&lt;br /&gt;    {&lt;br /&gt;        qreal xCoord = 0;&lt;br /&gt;        qreal yCoord = 0;&lt;br /&gt;        in &gt;&gt; xCoord;&lt;br /&gt;        in &gt;&gt; yCoord;&lt;br /&gt;        MyGraphicsItem* item = new MyGraphicsItem();&lt;br /&gt;        item-&gt;setPos(xCoord,yCoord);&lt;br /&gt;        scene-&gt;addItem(item);&lt;br /&gt;    }&lt;br /&gt;    QMessageBox::warning(this,"Success","Loaded Scene Items From File");&lt;br /&gt;    close();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;sl_loadSceneFromFile()  opens sceneData.txt file and reads its content into QDataStream instance.&lt;br /&gt;sceneData.txt file is located under LoadSceneFromQDataStream/LoadSceneFromQDataStream folder of the project. sceneData.txt file is created by the &lt;a href="http://tufangorel.blogspot.com/2011/06/serialize-qgraphicsscene-binary-data-by.html"&gt;previous sample&lt;/a&gt; application.&lt;br /&gt;&lt;br /&gt;First serialized data to the sceneData.txt file is the number of QGraphicsItems on the QGraphicsScene. It is read into the variable “itemListSize” from sceneData.txt file. Then for each QGraphicsItem on the QGraphicsScene, xCoordinate and yCoordinate of the QGraphicsItem is stored in the file in binary format. By reading x and y coordinate of the QGraphicsItem from sceneData.txt file, item’s position is set. After setting the pos of the QGraphicsItem, it is inserted into the list of QGraphicsItems on the QGraphicsScene by calling the addItem function of QGraphicsScene. &lt;br /&gt;&lt;br /&gt;Regenerated QGraphicsItem instance on the QGraphicsScene is a custom/derived QGprahicsItem and is defined in MyGraphicsItem.h file.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef MYGRAPHICSITEM_H&lt;br /&gt;#define MYGRAPHICSITEM_H&lt;br /&gt;#include &amp;lt;QGraphicsItem&amp;gt;&lt;br /&gt;class MyGraphicsItem : public QGraphicsItem&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    MyGraphicsItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);&lt;br /&gt;    ~MyGraphicsItem();&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;    QRectF boundingRect() const;&lt;br /&gt;&lt;br /&gt;    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;               QWidget *widget);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif // MYGRAPHICSITEM_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Custom QGraphicsItem contains constructor, destructor, boundingRect() and paint() methods.&lt;br /&gt;&lt;br /&gt;MyGraphicsItem.cpp file contains implementation details for the custom QGraphicsItem class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;MyGraphicsItem::MyGraphicsItem(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent,scene)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;MyGraphicsItem::~MyGraphicsItem(){}&lt;br /&gt;&lt;br /&gt;QRectF MyGraphicsItem::boundingRect() const&lt;br /&gt;{&lt;br /&gt;    qreal penWidth = 1;&lt;br /&gt;    return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,&lt;br /&gt;                  20 + penWidth, 20 + penWidth);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;           QWidget *widget)&lt;br /&gt;{&lt;br /&gt;    Q_UNUSED(widget)&lt;br /&gt;    Q_UNUSED(option)&lt;br /&gt;&lt;br /&gt;    QPen pen;&lt;br /&gt;    pen.setWidthF(2);&lt;br /&gt;    pen.setStyle(Qt::DashLine);&lt;br /&gt;    painter-&gt;setPen(pen);&lt;br /&gt;    painter-&gt;setBrush(QBrush(QColor(50,120,80)));&lt;br /&gt;    painter-&gt;drawRoundedRect(boundingRect(), 25, 25, Qt::RelativeSize);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When you run the application, a dialog with a "load scene from file" button is displayed.By clicking the qpushbutton, application searches for the sceneData.txt file and loads files content into the QGraphicsScene.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-0IpAJsAi-5M/TjB1mmU2LbI/AAAAAAAAAEU/f41Yf-dR3aQ/s1600/loadedItems.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 254px; height: 320px;" src="http://3.bp.blogspot.com/-0IpAJsAi-5M/TjB1mmU2LbI/AAAAAAAAAEU/f41Yf-dR3aQ/s320/loadedItems.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5634132439823953330" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;QYTGKR3Z93FP&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/OI6YeplACgM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/OI6YeplACgM/load-qgraphicsscene-from-qdatastream.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-NdS9r5yBboU/TjBt3EC8q_I/AAAAAAAAAEM/fQakw3lMt_0/s72-c/loadScene.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/07/load-qgraphicsscene-from-qdatastream.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-7711396110319487118</guid><pubDate>Tue, 21 Jun 2011 20:26:00 +0000</pubDate><atom:updated>2011-06-22T00:11:34.699+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGraphicsItem</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Serialize QGraphicsScene Binary Data By Using QDataStream</title><description>QGraphicsScene class enables easy management of QGraphicsItem instances in a 2D environment. QGraphicsScene acts as a container for custom QGraphicsItems. &lt;br /&gt;Custom QDialog with a QGraphicsView helps to visualize QGraphicsItems that are included in a QGraphicsScene. By using addItem() function of QGraphicsScene, custom QGraphicsItems can be added to the QGraphicsScene instance. QGprahicsItem binary data such as x() and y() coordinates can be serialized to a QFile by using QDataStream.&lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, SceneToDataStream.h, SceneToDataStream.cpp, MyGraphicsItem.h and MyGraphicsItem.cpp files.&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-8H9ZZBcF13I/TgEBGzluyHI/AAAAAAAAAD8/UZKPZObY-0o/s1600/sceneToDataStream.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 249px; height: 178px;" src="http://1.bp.blogspot.com/-8H9ZZBcF13I/TgEBGzluyHI/AAAAAAAAAD8/UZKPZObY-0o/s320/sceneToDataStream.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5620775026374396018" /&gt;&lt;/a&gt;&lt;br /&gt;SceneToDataStream.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += core gui&lt;br /&gt;TARGET = SceneToDataStream&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp\&lt;br /&gt;        SceneToDataStream.cpp \&lt;br /&gt;    MyGraphicsItem.cpp&lt;br /&gt;HEADERS  += SceneToDataStream.h \&lt;br /&gt;    MyGraphicsItem.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "SceneToDataStream.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    Dialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;SceneToDataStream.h file is the extended QDialog class header file.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef SCENETODATASTREAM_H&lt;br /&gt;#define SCENETODATASTREAM_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;&lt;br /&gt;class QGraphicsScene;&lt;br /&gt;class MyGraphicsItem;&lt;br /&gt;class QGraphicsView;&lt;br /&gt;class QVBoxLayout;&lt;br /&gt;&lt;br /&gt;class Dialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    Dialog(QWidget *parent = 0);&lt;br /&gt;    ~Dialog();&lt;br /&gt;&lt;br /&gt;public slots:&lt;br /&gt;    void sl_saveSceneToFile();&lt;br /&gt;&lt;br /&gt;private:&lt;br /&gt;    QGraphicsScene* scene;&lt;br /&gt;    MyGraphicsItem* item;&lt;br /&gt;    QGraphicsView* view;&lt;br /&gt;    QVBoxLayout* layout;&lt;br /&gt;    QPushButton* btnSave;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif // SCENETODATASTREAM_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;SceneToDataStream.cpp file contains implementation details for extended QDialog class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "SceneToDataStream.h"&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;&lt;br /&gt;#include &amp;lt;QGraphicsScene&amp;gt;&lt;br /&gt;#include &amp;lt;QGraphicsView&amp;gt;&lt;br /&gt;#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QFile&amp;gt;&lt;br /&gt;#include &amp;lt;QList&amp;gt;&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;#include &amp;lt;QDir&amp;gt;&lt;br /&gt;&lt;br /&gt;Dialog::Dialog(QWidget *parent)&lt;br /&gt;    : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    scene = new QGraphicsScene(this);&lt;br /&gt;    item = new MyGraphicsItem();&lt;br /&gt;    item-&gt;setPos(34,35);&lt;br /&gt;    scene-&gt;addItem(item);&lt;br /&gt;    view = new QGraphicsView(scene,this);&lt;br /&gt;    layout = new QVBoxLayout(this);&lt;br /&gt;    layout-&gt;addWidget(view);&lt;br /&gt;    btnSave = new QPushButton("Save Scene To File");&lt;br /&gt;    connect(btnSave, SIGNAL(clicked()), this, SLOT(sl_saveSceneToFile()));&lt;br /&gt;    layout-&gt;addWidget(btnSave);&lt;br /&gt;    setLayout(layout);&lt;br /&gt;    resize(270,200);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Dialog::~Dialog()&lt;br /&gt;{&lt;br /&gt;    delete btnSave;&lt;br /&gt;    delete layout;&lt;br /&gt;    delete item;&lt;br /&gt;    delete scene;&lt;br /&gt;    delete view;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Dialog::sl_saveSceneToFile()&lt;br /&gt;{&lt;br /&gt;    QString fileName = QDir::currentPath().append("/sceneData.txt");&lt;br /&gt;    QFile file(fileName);&lt;br /&gt;    if (!file.open(QIODevice::WriteOnly))&lt;br /&gt;    {&lt;br /&gt;            return;&lt;br /&gt;    }&lt;br /&gt;    QDataStream out(&amp;file);&lt;br /&gt;    QList&amp;lt;QGraphicsItem*&amp;gt; itemList = scene-&gt;items();&lt;br /&gt;    int itemListSize = itemList.size();&lt;br /&gt;    out &lt;&lt; itemListSize;&lt;br /&gt;    foreach( QGraphicsItem* item, itemList)&lt;br /&gt;    {&lt;br /&gt;        out &lt;&lt; item-&gt;x();&lt;br /&gt;        out &lt;&lt; item-&gt;y();&lt;br /&gt;    }&lt;br /&gt;    QMessageBox::warning(this,"Success","Saved Scene Data to File");&lt;br /&gt;    close();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;sl_saveSceneToFile() slot of Dialog class is connected to QPushButton clicked signal and serializes number of all the items on the scene with item x() and y() coordinates respectively.&lt;br /&gt;&lt;br /&gt;MyGraphicsItem is a derived custom QGraphicsItem class that implements boundingRect() and paint() functions of the parent. MyGraphicsItem is a rectangular derived QGraphicsItem and added to the QGraphicsScene.&lt;br /&gt;MyGraphicsItem.h file contains custom QGraphicsItem class declaration.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef MYGRAPHICSITEM_H&lt;br /&gt;#define MYGRAPHICSITEM_H&lt;br /&gt;#include &amp;lt;QGraphicsItem&amp;gt;&lt;br /&gt;class MyGraphicsItem : public QGraphicsItem&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;    MyGraphicsItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);&lt;br /&gt;    ~MyGraphicsItem();&lt;br /&gt;&lt;br /&gt;protected:&lt;br /&gt;    QRectF boundingRect() const;&lt;br /&gt;&lt;br /&gt;    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;               QWidget *widget);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif // MYGRAPHICSITEM_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;MyGraphicsItem.cpp file contains implementation details for custom QGraphicsItem class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "MyGraphicsItem.h"&lt;br /&gt;#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;MyGraphicsItem::MyGraphicsItem(QGraphicsItem* parent, QGraphicsScene* scene) : QGraphicsItem(parent,scene)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;MyGraphicsItem::~MyGraphicsItem(){}&lt;br /&gt;&lt;br /&gt;QRectF MyGraphicsItem::boundingRect() const&lt;br /&gt;{&lt;br /&gt;    qreal penWidth = 1;&lt;br /&gt;    return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,&lt;br /&gt;                  20 + penWidth, 20 + penWidth);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,&lt;br /&gt;           QWidget *widget)&lt;br /&gt;{&lt;br /&gt;    Q_UNUSED(widget)&lt;br /&gt;    Q_UNUSED(option)&lt;br /&gt;&lt;br /&gt;    QPen pen;&lt;br /&gt;    pen.setWidthF(2);&lt;br /&gt;    pen.setStyle(Qt::DashLine);&lt;br /&gt;    painter-&gt;setPen(pen);&lt;br /&gt;    painter-&gt;setBrush(QBrush(QColor(50,120,80)));&lt;br /&gt;    painter-&gt;drawRoundedRect(boundingRect(), 25, 25, Qt::RelativeSize);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;sceneData.txt is the produced file that contains serialized binary data.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-HUZRtJdAd5U/TgEGvTV6lCI/AAAAAAAAAEE/ZmuKM5IDJ2M/s1600/savedScene.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 243px; height: 320px;" src="http://3.bp.blogspot.com/-HUZRtJdAd5U/TgEGvTV6lCI/AAAAAAAAAEE/ZmuKM5IDJ2M/s320/savedScene.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5620781219650901026" /&gt;&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/cQzYQ70T94E" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/cQzYQ70T94E/serialize-qgraphicsscene-binary-data-by.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-8H9ZZBcF13I/TgEBGzluyHI/AAAAAAAAAD8/UZKPZObY-0o/s72-c/sceneToDataStream.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/06/serialize-qgraphicsscene-binary-data-by.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8949268395709428583</guid><pubDate>Wed, 08 Jun 2011 17:16:00 +0000</pubDate><atom:updated>2011-06-08T20:32:27.076+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Reimplementing closeEvent of QDialog</title><description>It is always required to ask the user before closing the dialog whether he/she is sure about that. closeEvent event handler can also be used to save the position of the dialog before it is being closed. &lt;span style="font-weight:bold;"&gt;closeEvent of QDialog&lt;/span&gt; is being called before than the destructor of the extended QDialog instance.&lt;br /&gt;Sample extended QDialog shows a QMessageBox instance when the user clicks on the close button that is placed at the top right corner of the dialog and asks for confirmation before closing the dialog. Depending on the user’s selection, dialog closes or stays open.&lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, QDialogCloseEvent.h and QDialogCloseEvent.cpp files.&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-rY8XfZNjYlA/Te-v2kDMGZI/AAAAAAAAADs/FZDuXD7UlY8/s1600/project_structure.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 283px; height: 142px;" src="http://4.bp.blogspot.com/-rY8XfZNjYlA/Te-v2kDMGZI/AAAAAAAAADs/FZDuXD7UlY8/s320/project_structure.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615900612279146898" /&gt;&lt;/a&gt;&lt;br /&gt;QDialogCloseEvent.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QT       += core gui&lt;br /&gt;TARGET    = QDialogCloseEvent&lt;br /&gt;TEMPLATE  = app&lt;br /&gt;SOURCES  += main.cpp\&lt;br /&gt;         QDialogCloseEvent.cpp&lt;br /&gt;HEADERS  += QDialogCloseEvent.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "QDialogCloseEvent.h"&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    Dialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;QDialogCloseEvent.h file is the extended QDialog class header file.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef QDIALOGCLOSEEVENT_H&lt;br /&gt;#define QDIALOGCLOSEEVENT_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;class Dialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;public:&lt;br /&gt;    Dialog(QWidget *parent = 0);&lt;br /&gt;    ~Dialog();&lt;br /&gt;protected:&lt;br /&gt;    void closeEvent(QCloseEvent * event);&lt;br /&gt;};&lt;br /&gt;#endif // QDIALOGCLOSEEVENT_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;QDialogCloseEvent.cpp file contains implementation details for extended QDialog class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "QDialogCloseEvent.h"&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;#include &amp;lt;QCloseEvent&amp;gt;&lt;br /&gt;Dialog::Dialog(QWidget *parent) : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    resize(300,90);&lt;br /&gt;}&lt;br /&gt;Dialog::~Dialog(){}&lt;br /&gt;void Dialog::closeEvent(QCloseEvent *event)&lt;br /&gt;{&lt;br /&gt;    QMessageBox msgBox;&lt;br /&gt;    msgBox.setText("Are you sure you want to close?");&lt;br /&gt;    msgBox.setStandardButtons(QMessageBox::Close | QMessageBox::Cancel);&lt;br /&gt;    msgBox.setDefaultButton(QMessageBox::Close);&lt;br /&gt;    int result = msgBox.exec();&lt;br /&gt;    switch (result) {&lt;br /&gt;      case QMessageBox::Close:&lt;br /&gt;          event-&gt;accept();&lt;br /&gt;          break;&lt;br /&gt;      case QMessageBox::Cancel:&lt;br /&gt;          event-&gt;ignore();&lt;br /&gt;          break;&lt;br /&gt;      default:&lt;br /&gt;          QDialog::closeEvent(event);&lt;br /&gt;          break;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Custom QDialog with QMessageBox:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-kMMww5xjQKo/Te-yGMVbrdI/AAAAAAAAAD0/4PqUpszCTsw/s1600/close_event.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 247px;" src="http://1.bp.blogspot.com/-kMMww5xjQKo/Te-yGMVbrdI/AAAAAAAAAD0/4PqUpszCTsw/s320/close_event.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615903079814376914" /&gt;&lt;/a&gt;&lt;br /&gt;Application created by QT Creator and uses Qt4.7 .&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/q7_7GZWftFM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/q7_7GZWftFM/reimplementing-closeevent-of-qdialog.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-rY8XfZNjYlA/Te-v2kDMGZI/AAAAAAAAADs/FZDuXD7UlY8/s72-c/project_structure.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/06/reimplementing-closeevent-of-qdialog.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-2344070852462766886</guid><pubDate>Tue, 07 Jun 2011 18:17:00 +0000</pubDate><atom:updated>2011-06-07T21:55:45.583+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Show QImage in a QLabel</title><description>&lt;span style="font-weight:bold;"&gt;QImage&lt;/span&gt; enables to construct images from file paths on the disk. Constructed QImages can be displayed in a QLabel. By setting the pixmap value of QLabel from &lt;span style="font-weight:bold;"&gt;setPixmap&lt;/span&gt; function, &lt;span style="font-weight:bold;"&gt;QLabel&lt;/span&gt; displays content of &lt;span style="font-weight:bold;"&gt;QImage&lt;/span&gt;.&lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, ShowQImageDialog.h and ShowQImageDialog.cpp files.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;ShowQImageDialog&lt;/span&gt; constructor creates a QGridLayout instance that is containing a QScrollArea inside it and displays the image in this area.&lt;br /&gt;Project Directory Structure in &lt;span style="font-weight:bold;"&gt;Qt Creator IDE&lt;/span&gt; :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-nW049dMWehc/Te5xB4TL-5I/AAAAAAAAADc/hcjETadMtjI/s1600/project_structure.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 282px; height: 144px;" src="http://3.bp.blogspot.com/-nW049dMWehc/Te5xB4TL-5I/AAAAAAAAADc/hcjETadMtjI/s320/project_structure.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615550062484257682" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;ShowQImageDialog.pro is the project configuration file and contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;TARGET = ShowQImageDialog&lt;br /&gt;CONFIG   += core gui&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp \&lt;br /&gt;    ShowQImageDialog.cpp&lt;br /&gt;HEADERS += \&lt;br /&gt;    ShowQImageDialog.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the &lt;span style="font-weight:bold;"&gt;custom QDialog&lt;/span&gt; instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "ShowQImageDialog.h"&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    ShowQImageDialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ShowQImageDialog.h file is the extended QDialog class header file.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef SHOWQIMAGEDIALOG_H&lt;br /&gt;#define SHOWQIMAGEDIALOG_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;#include &amp;lt;QGridLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QScrollArea&amp;gt;&lt;br /&gt;#include &amp;lt;QLabel&amp;gt;&lt;br /&gt;#include &amp;lt;QImage&amp;gt;&lt;br /&gt;&lt;br /&gt;class ShowQImageDialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;&lt;br /&gt;public:&lt;br /&gt;    ShowQImageDialog(QWidget *parent = 0);&lt;br /&gt;    ~ShowQImageDialog();&lt;br /&gt;private:&lt;br /&gt;    QGridLayout* gridLayout;&lt;br /&gt;    QImage* inputImg;&lt;br /&gt;    QLabel* imgDisplayLabel;&lt;br /&gt;    QScrollArea* scrollArea;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif // SHOWQIMAGEDIALOG_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ShowQImageDialog.cpp file contains implementation details for extended QDialog class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "ShowQImageDialog.h"&lt;br /&gt;ShowQImageDialog::ShowQImageDialog(QWidget *parent) : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    gridLayout = new QGridLayout();&lt;br /&gt;    inputImg = new QImage("/home/tufan/wallpaper.png");&lt;br /&gt;    imgDisplayLabel = new QLabel("");&lt;br /&gt;    imgDisplayLabel-&gt;setPixmap(QPixmap::fromImage(*inputImg));&lt;br /&gt;    imgDisplayLabel-&gt;adjustSize();&lt;br /&gt;    scrollArea = new QScrollArea();&lt;br /&gt;    scrollArea-&gt;setWidget(imgDisplayLabel);&lt;br /&gt;    scrollArea-&gt;setMinimumSize(256,256);&lt;br /&gt;    scrollArea-&gt;setMaximumSize(512,512);&lt;br /&gt;    gridLayout-&gt;addWidget(scrollArea,0,0);&lt;br /&gt;    setLayout(gridLayout);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;ShowQImageDialog::~ShowQImageDialog()&lt;br /&gt;{&lt;br /&gt;    delete inputImg;&lt;br /&gt;    delete imgDisplayLabel;&lt;br /&gt;    delete scrollArea;&lt;br /&gt;    delete gridLayout;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ShowQImageDialog:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-dQGPVg3IVzA/Te5zYFz_CkI/AAAAAAAAADk/zoWeIayvZG4/s1600/showQImageDialog.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 268px;" src="http://4.bp.blogspot.com/-dQGPVg3IVzA/Te5zYFz_CkI/AAAAAAAAADk/zoWeIayvZG4/s320/showQImageDialog.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615552643091860034" /&gt;&lt;/a&gt;&lt;br /&gt;Application created by QT Creator and uses Qt4.7 .&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/bfoUW04TvC8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/bfoUW04TvC8/show-qimage-in-qlabel.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-nW049dMWehc/Te5xB4TL-5I/AAAAAAAAADc/hcjETadMtjI/s72-c/project_structure.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/06/show-qimage-in-qlabel.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-6631723236221685730</guid><pubDate>Tue, 07 Jun 2011 17:24:00 +0000</pubDate><atom:updated>2011-06-07T21:14:36.251+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Check for valid file extension provided by QFileDialog</title><description>QFileDialog is used to select files from a specific directory. getOpenFileName() static function of QFileDialog returns the name of the selected file. Also, a filter can be set for the type of the file selected by the user by separating types with ';;'.&lt;br /&gt;Ex:&lt;br /&gt;"All Files (*.*);;JPEG (*.jpeg *.jpg);;PNG (*.png)"&lt;br /&gt; In order to check for file extension of a file name provided by BrowseDialog which is extending QDialog and containing QFileDialog in its sl_browseImage() slot,&lt;br /&gt;bool &lt;span style="font-weight:bold;"&gt;isValidImageFile&lt;/span&gt;(const QString&amp; str)&lt;br /&gt;function is implemented.&lt;br /&gt; isValidImageFile function takes the full path of the file and splits it into pieces to find the file extension from the original QString instance.&lt;br /&gt; File extension is placed after the last period character, so the last member of the QStringList contains the file extension that we are looking for.&lt;br /&gt; By getting the upper case of the file extension which is provided by the client, we can search for a suitable match in our accepted file extension list. If the provided file extension is not in our list, then the derived custom QDialog opens a QMessageBox and gives a warning to the client.&lt;br /&gt;Sample project started as a QT Gui Application and contains main.cpp, BrowseFileDialog.h and BrowseFileDialog.cpp files.&lt;br /&gt;&lt;br /&gt;Project Directory Structure in Qt Creator IDE :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-vNykcGgFXP0/Te5qRb5pXmI/AAAAAAAAADU/5zZAL5ssgzo/s1600/project_structure.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 283px; height: 141px;" src="http://3.bp.blogspot.com/-vNykcGgFXP0/Te5qRb5pXmI/AAAAAAAAADU/5zZAL5ssgzo/s320/project_structure.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615542633157451362" /&gt;&lt;/a&gt;&lt;br /&gt;BrowseFileDialog.pro is the project configuration file contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;TARGET = BrowseFileDialog&lt;br /&gt;CONFIG   += core gui&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp \&lt;br /&gt;    BrowseFileDialog.cpp&lt;br /&gt;HEADERS += \&lt;br /&gt;    BrowseFileDialog.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the custom QDialog instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "BrowseFileDialog.h"&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;    QApplication a(argc, argv);&lt;br /&gt;    BrowseFileDialog w;&lt;br /&gt;    w.show();&lt;br /&gt;    return a.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;BrowseFileDialog.h file is the derived QDialog class header file. Custom QDialog contains signals and slots to be associated with buttons on the dialog.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef BROWSEFILEDIALOG_H&lt;br /&gt;#define BROWSEFILEDIALOG_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;#include &amp;lt;QLineEdit&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QLabel&amp;gt;&lt;br /&gt;&lt;br /&gt;class BrowseFileDialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;public:&lt;br /&gt;    BrowseFileDialog(QWidget *parent = 0);&lt;br /&gt;    ~BrowseFileDialog();&lt;br /&gt;public slots:&lt;br /&gt;    void sl_browseImage();&lt;br /&gt;private:&lt;br /&gt;    void initLayout();&lt;br /&gt;    void initConnections();&lt;br /&gt;    bool isValidImageFile(const QString&amp; str);&lt;br /&gt;    QLabel* label;&lt;br /&gt;    QLineEdit* lineEdit;&lt;br /&gt;    QPushButton* pushButtonBrowse;&lt;br /&gt;    QPushButton* pushButtonOK;&lt;br /&gt;    QPushButton* pushButtonCancel;&lt;br /&gt;};&lt;br /&gt;#endif // BROWSEFILEDIALOG_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;BrowseFileDialog.cpp file contains implementation details for extended QDialog class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "BrowseFileDialog.h"&lt;br /&gt;#include &amp;lt;QHBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QFileDialog&amp;gt;&lt;br /&gt;#include &amp;lt;QString&amp;gt;&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;#include &amp;lt;QSpacerItem&amp;gt;&lt;br /&gt;BrowseFileDialog::BrowseFileDialog(QWidget *parent) : QDialog(parent)&lt;br /&gt;{&lt;br /&gt;    initLayout();&lt;br /&gt;    initConnections();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BrowseFileDialog::~BrowseFileDialog()&lt;br /&gt;{&lt;br /&gt;    delete label;&lt;br /&gt;    delete lineEdit;&lt;br /&gt;    delete pushButtonBrowse;&lt;br /&gt;    delete pushButtonOK;&lt;br /&gt;    delete pushButtonCancel;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void BrowseFileDialog::initLayout()&lt;br /&gt;{&lt;br /&gt;    QGridLayout* mainLayout = new QGridLayout(this);&lt;br /&gt;    QHBoxLayout* hBoxLayout = new QHBoxLayout();&lt;br /&gt;    hBoxLayout-&gt;setSpacing(0);&lt;br /&gt;    hBoxLayout-&gt;setMargin(0);&lt;br /&gt;    label = new QLabel("Image File Path :");&lt;br /&gt;    lineEdit = new QLineEdit(this);&lt;br /&gt;    lineEdit-&gt;setReadOnly(true);&lt;br /&gt;    pushButtonBrowse = new QPushButton("Browse...");&lt;br /&gt;    hBoxLayout-&gt;addWidget(label);&lt;br /&gt;    hBoxLayout-&gt;addWidget(lineEdit);&lt;br /&gt;    hBoxLayout-&gt;addWidget(pushButtonBrowse);&lt;br /&gt;    QHBoxLayout* actionWidgetsHBoxLayout = new QHBoxLayout();&lt;br /&gt;    pushButtonCancel = new QPushButton("Cancel");&lt;br /&gt;    pushButtonOK = new QPushButton("OK");&lt;br /&gt;    actionWidgetsHBoxLayout-&gt;addStretch();&lt;br /&gt;    actionWidgetsHBoxLayout-&gt;addWidget(pushButtonCancel);&lt;br /&gt;    actionWidgetsHBoxLayout-&gt;addWidget(pushButtonOK);&lt;br /&gt;    mainLayout-&gt;addLayout(hBoxLayout,0,0);&lt;br /&gt;    mainLayout-&gt;addLayout(actionWidgetsHBoxLayout,1,0);&lt;br /&gt;    setLayout(mainLayout);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void BrowseFileDialog::initConnections()&lt;br /&gt;{&lt;br /&gt;    connect(pushButtonBrowse, SIGNAL(clicked()), this, SLOT(sl_browseImage()));&lt;br /&gt;    connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept()));&lt;br /&gt;    connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void BrowseFileDialog::sl_browseImage()&lt;br /&gt;{&lt;br /&gt;    QString inputImagePath=QFileDialog::getOpenFileName(this,tr("Select Image File"),QDir::currentPath(),&lt;br /&gt;                                                        tr("All Files (*.*);;JPEG (*.jpeg *.jpg);;PNG (*.png)"));&lt;br /&gt;    if(isValidImageFile(inputImagePath))&lt;br /&gt;        lineEdit-&gt;setText(inputImagePath);&lt;br /&gt;    else {&lt;br /&gt;            QMessageBox::information(this, tr("Error!"),&lt;br /&gt;                    tr("Please Provide a valid input image with JPG,JPEG or PNG extension!"));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bool BrowseFileDialog::isValidImageFile(const QString&amp; strImageFileName)&lt;br /&gt;{&lt;br /&gt;    QStringList acceptedImageFileTypeList;&lt;br /&gt;    acceptedImageFileTypeList &lt;&lt; "JPG"&lt;&lt; "JPEG" &lt;&lt; "PNG";&lt;br /&gt;    QStringList splittedStrList = strImageFileName.split(".");&lt;br /&gt;    if( ((splittedStrList.size())-1) &gt;= 0) {&lt;br /&gt;        QString fileExtensionToCheck = splittedStrList[((splittedStrList.size())-1)];&lt;br /&gt;        if( acceptedImageFileTypeList.contains(fileExtensionToCheck.toUpper()) )&lt;br /&gt;            return true;&lt;br /&gt;        else&lt;br /&gt;            return false;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;        return false;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;BrowseFileDialog:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-rfM1T7b6twA/Te5kNKYc-PI/AAAAAAAAAC8/gXzAByjgubY/s1600/browse_dialog.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 97px;" src="http://1.bp.blogspot.com/-rfM1T7b6twA/Te5kNKYc-PI/AAAAAAAAAC8/gXzAByjgubY/s320/browse_dialog.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5615535962665580786" /&gt;&lt;/a&gt;&lt;br /&gt;Application created by QT Creator and uses Qt4.7 .&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/rmrMFZX2I0Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/rmrMFZX2I0Q/check-for-valid-file-extension-provided.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-vNykcGgFXP0/Te5qRb5pXmI/AAAAAAAAADU/5zZAL5ssgzo/s72-c/project_structure.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/06/check-for-valid-file-extension-provided.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-2934736439105654303</guid><pubDate>Sat, 07 May 2011 21:40:00 +0000</pubDate><atom:updated>2011-05-15T22:51:41.809+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Create Custom QDialogs With QLayout Classes</title><description>Qt Designer is used to design user interfaces for QT applications. In addition to using QT Designer to generate user interfaces, you can populate your dialogs with widgets on them dynamically at runtime by using layout classes. To achieve this, you need to extend qdialog class and add widgets to your derived qdialog instance dynamically at runtime.&lt;br /&gt; Qt's layout classes are used to place widgets on parent dialogs or widgets. Instead of manually placing widgets on main containers and creating static user interfaces, layout classes help to place widgets easily. There are different QT layout classes but QHBoxLayout and QVBoxLayout are the most popular of them. By using the addWidget() method of layout class, you place items on the layout. After adding widgets to the layout properly, it is required to call setLayout() method of the main container to make layout visible on it.&lt;br /&gt; Sample project started as a QT Gui Application and contains main.cpp, DynamicQDialog.h and DynamicQDialog.cpp files.&lt;br /&gt;DynamicDialog.pro is the project configuration file contains:&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;TARGET = DynamicDialog&lt;br /&gt;CONFIG   += qt gui&lt;br /&gt;TEMPLATE = app&lt;br /&gt;SOURCES += main.cpp \&lt;br /&gt;    DynamicQDialog.cpp&lt;br /&gt;HEADERS += \&lt;br /&gt;    DynamicQDialog.h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;main.cpp file contains the custom QDialog instance and shows it.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "DynamicQDialog.h"&lt;br /&gt;int main(int argc, char *argv[]) {&lt;br /&gt;    QApplication app(argc, argv);&lt;br /&gt;    DynamicQDialog dialog;&lt;br /&gt;    dialog.show();&lt;br /&gt;    return app.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;DynamicQDialog.h file is the derived QDialog class header file. Custom QDialog contains signals and slots to be associated with buttons on the dialog.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#ifndef DYNAMICQDIALOG_H&lt;br /&gt;#define DYNAMICQDIALOG_H&lt;br /&gt;#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;class DynamicQDialog : public QDialog&lt;br /&gt;{&lt;br /&gt;    Q_OBJECT&lt;br /&gt;public:&lt;br /&gt;    DynamicQDialog(QWidget * parent = 0, Qt::WindowFlags f = 0);&lt;br /&gt;    ~DynamicQDialog();&lt;br /&gt;public slots:&lt;br /&gt;    void sl_accept();&lt;br /&gt;    void sl_cancel();&lt;br /&gt;signals:&lt;br /&gt;};&lt;br /&gt;#endif // DYNAMICQDIALOG_H&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;DynamicQDialog.cpp file contains implementation details for derived QDialog class. 2 QPushButtons added to the QHBoxLayout dynamically at runtime and displayed on the DynamicQDialog instance.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "DynamicQDialog.h"&lt;br /&gt;#include &amp;lt;QHBoxLayout&amp;gt;&lt;br /&gt;#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;#include &amp;lt;QTextEdit&amp;gt;&lt;br /&gt;#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;&lt;br /&gt;DynamicQDialog::DynamicQDialog(QWidget* parent, Qt::WindowFlags flags): QDialog( parent, flags )&lt;br /&gt;{&lt;br /&gt;    QGridLayout* mainGrid = new QGridLayout;&lt;br /&gt;    QVBoxLayout* topLayout = new QVBoxLayout;&lt;br /&gt;    topLayout-&gt;addWidget(new QTextEdit);&lt;br /&gt;    mainGrid-&gt;addLayout(topLayout,0,0);&lt;br /&gt;&lt;br /&gt;    QHBoxLayout* hLayout = new QHBoxLayout;&lt;br /&gt;    QPushButton* btn;&lt;br /&gt;    for( int i=0; i&lt;2; i++ ) {&lt;br /&gt;        if( i == 0 ) {&lt;br /&gt;            btn = new QPushButton("OK");&lt;br /&gt;            connect(btn, SIGNAL(clicked()), this, SLOT(sl_accept()));&lt;br /&gt;        }&lt;br /&gt;        else if( i == 1 ) {&lt;br /&gt;            btn = new QPushButton("Cancel");&lt;br /&gt;            connect(btn, SIGNAL(clicked()), this, SLOT(sl_cancel()));&lt;br /&gt;        }&lt;br /&gt;        hLayout-&gt;addWidget(btn);&lt;br /&gt;    }&lt;br /&gt;    mainGrid-&gt;addLayout(hLayout,1,0);&lt;br /&gt;&lt;br /&gt;    setLayout(mainGrid);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;DynamicQDialog::~DynamicQDialog(){}&lt;br /&gt;&lt;br /&gt;void DynamicQDialog::sl_accept(){&lt;br /&gt;    QMessageBox msgBox;&lt;br /&gt;    msgBox.setText("OK Clicked!");&lt;br /&gt;    msgBox.exec();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void DynamicQDialog::sl_cancel(){&lt;br /&gt;    QMessageBox msgBox;&lt;br /&gt;    msgBox.setText("Cancel Clicked!");&lt;br /&gt;    msgBox.exec();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-MSmPegZ9jXk/TdAuZJcMhRI/AAAAAAAAACw/eb6F1Hnev6k/s1600/dynamicDialog.PNG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 286px; height: 237px;" src="http://3.bp.blogspot.com/-MSmPegZ9jXk/TdAuZJcMhRI/AAAAAAAAACw/eb6F1Hnev6k/s320/dynamicDialog.PNG" border="0" alt=""id="BLOGGER_PHOTO_ID_5607032545642054930" /&gt;&lt;/a&gt;&lt;br /&gt;Application created by QT Creator and uses Qt4.7 .&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/ZPLmz-AYAMY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/ZPLmz-AYAMY/create-custom-qdialogs-with-qlayout.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-MSmPegZ9jXk/TdAuZJcMhRI/AAAAAAAAACw/eb6F1Hnev6k/s72-c/dynamicDialog.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2011/05/create-custom-qdialogs-with-qlayout.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8912747132986073164</guid><pubDate>Tue, 23 Nov 2010 17:48:00 +0000</pubDate><atom:updated>2010-11-23T19:52:54.450+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Using qmake from WinXP Command Line</title><description>qmake is used to create Makefiles from .pro files for QT projects.&lt;br /&gt;qmake uses what you put in your project (.pro) files to decide what should go in the Makefiles it produces.&lt;br /&gt;&lt;br /&gt;In order to test your installed qmake version type:&lt;br /&gt;C:\&gt;qmake -v&lt;br /&gt;from command line but it produces an error message like:&lt;br /&gt;'qmake' is not recognized as an internal or external command,&lt;br /&gt;operable program or batch file.&lt;br /&gt;&lt;br /&gt;In order to use qmake from winXP command line set following variables:&lt;br /&gt;1-) Set the QMAKESPEC environment variable to point to a directory containing a description of your platform and compiler&lt;br /&gt;2-) Add the 'qmake' executable to your PATH &lt;br /&gt;&lt;br /&gt;I have installed QT4.6 at C:\Qt\4.6.0 , it can be at a different location on your disk. Execute following commands from command line respectively:&lt;br /&gt;&lt;br /&gt;C:\&gt;set QMAKESPEC=C:\Qt\4.6.0\mkspecs\win32-msvc&lt;br /&gt;C:\&gt;set PATH=%PATH%;C:\Qt\4.6.0\qmake&lt;br /&gt;&lt;br /&gt;And then to check it type following.&lt;br /&gt;&lt;br /&gt;C:\&gt;qmake -v&lt;br /&gt;QMake version 2.01a&lt;br /&gt;&lt;br /&gt;Now you can use qmake to generate Makefiles from your .pro files.&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/wC3tOFG28TM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/wC3tOFG28TM/using-qmake-from-winxp-command-line.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/11/using-qmake-from-winxp-command-line.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-7312157214538654324</guid><pubDate>Mon, 25 Oct 2010 17:45:00 +0000</pubDate><atom:updated>2010-10-25T21:09:44.278+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Log Time, Date, FileName, FunctionName, LineNumber for QT Applications in C++</title><description>Logging provides developers with detailed information about program flow. Logging also makes tracing of exceptions occured easier at run-time. By including date, time, filename, functionname, linenumber into a text file; it becomes a helpful guide for program flow trace. C++ comes with macros that are usable for logging purposes.&lt;br /&gt;  "__FILE__" macro gives information about the curent fileName and returns a string. "__FUNCTION__" macro gives information about the name of the current function and returns a string. "__LINE__" macro gives information about the current line number and returns an integer value. These are ANSI-Compliant Predefined Macros.&lt;br /&gt;Logger.h file contains declaration for Log class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;fstream&amp;gt;&lt;br /&gt;#include &amp;lt;QString&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;class Log {&lt;br /&gt;public:&lt;br /&gt; Log();&lt;br /&gt; ~Log();&lt;br /&gt; void trace(QString fileName, QString functionName, int lineNumber);&lt;br /&gt;private:&lt;br /&gt; ofstream myFile;&lt;br /&gt; char stime[9];&lt;br /&gt; char sdate[9];&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Logger.cpp file contains implementation for Log class. trace() method takes fileName, functionName and lineNumber as parameters.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;fstream&amp;gt;&lt;br /&gt;#include "Logger.h"&lt;br /&gt;#include &amp;lt;time.h&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;Log::Log() {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Log::trace(QString fileName, QString functionName, int lineNumber) {&lt;br /&gt; _strtime(stime);&lt;br /&gt; _strdate(sdate);&lt;br /&gt; myFile.open("C:\\example.txt", fstream::in | fstream::out | fstream::app);&lt;br /&gt; myFile&amp;lt;&amp;lt;"Date:"&amp;lt;&amp;lt;sdate&amp;lt;&amp;lt;";"&amp;lt;&amp;lt;" Time:"&amp;lt;&amp;lt;stime&amp;lt;&amp;lt;";"&amp;lt;&amp;lt;" FileName:"&amp;lt;&amp;lt;qPrintable(fileName)&amp;lt;&amp;lt;";"&amp;lt;&amp;lt;" FunctionName:"&amp;lt;&amp;lt;qPrintable(functionName)&amp;lt;&amp;lt;";"&amp;lt;&amp;lt;" LineNo:"&amp;lt;&amp;lt;lineNumber&amp;lt;&amp;lt;endl;&lt;br /&gt; myFile.close(); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Log::~Log(){&lt;br /&gt; myFile.close();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;main.cpp file uses Log class trace method for logging purposes.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "logger.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;   Log* logger = new Log();&lt;br /&gt;   logger-&gt;trace(__FILE__, __FUNCTION__, __LINE__);&lt;br /&gt;   return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;trace method produces the output to the example.txt file that is located under the c:\ root directory. Sample output is generated as follows:&lt;br /&gt;Date:10/25/10; Time:21:07:25; FileName:.\main.cpp; FunctionName:main; LineNo:5&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/1X79inGBYdk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/1X79inGBYdk/log-time-date-filename-functionname.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/10/log-time-date-filename-functionname.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-699797757545415167</guid><pubDate>Tue, 19 Oct 2010 20:02:00 +0000</pubDate><atom:updated>2010-10-19T23:33:12.790+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QGraphicsItem</category><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Type of Custom QGraphicsItem on the QGraphicsScene</title><description>Applications that contain different kinds of derived QGraphicsItem instances need to identify that instances to achieve different operations on them at runtime.&lt;br /&gt;  "int QGraphicsItem::type() const [virtual]" method of QGraphicsItem class enables the clients to check for the type of the custom QGraphicsItem. Each unique QGraphicsItem instance returns a unique integer value from the type() method.&lt;br /&gt;  For custom QGraphicsItem classes it is also required to implement &lt;br /&gt;"QRectF QGraphicsItem::boundingRect(void) const"&lt;br /&gt;and&lt;br /&gt;"void QGraphicsItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)"&lt;br /&gt;methods additionally.&lt;br /&gt;&lt;br /&gt;"CustomGraphicsItems.h" file contains TextItem and LineItem class definitions.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QGraphicsItem&amp;gt;&lt;br /&gt;class TextItem : public QGraphicsItem {&lt;br /&gt;public:&lt;br /&gt; enum { Type = UserType + 1 };&lt;br /&gt; int type() const { return Type; }&lt;br /&gt; TextItem(QGraphicsItem* parent = 0 );&lt;br /&gt; ~TextItem();&lt;br /&gt;protected:&lt;br /&gt; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );&lt;br /&gt; QRectF boundingRect() const;&lt;br /&gt;};&lt;br /&gt;class LineItem : public QGraphicsItem {&lt;br /&gt;public:&lt;br /&gt; enum { Type = UserType + 2 };&lt;br /&gt; int type() const { return Type; }&lt;br /&gt; LineItem(QGraphicsItem* parent = 0);&lt;br /&gt; ~LineItem();&lt;br /&gt;protected:&lt;br /&gt; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );&lt;br /&gt; QRectF boundingRect() const;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Each custom QGraphicsItem instance is uniquely identified in the enum .&lt;br /&gt;&lt;br /&gt;"CustomGraphicsItems.cpp" file contains implementation for TextItem and LineItem classes.&lt;br /&gt;&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "CustomGraphicsItems.h"&lt;br /&gt;TextItem ::TextItem(QGraphicsItem* parent) : QGraphicsItem(parent) {}&lt;br /&gt;TextItem::~TextItem() {}&lt;br /&gt;QRectF TextItem::boundingRect() const {&lt;br /&gt; return QRectF();&lt;br /&gt;}&lt;br /&gt;void TextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {}&lt;br /&gt;LineItem ::LineItem(QGraphicsItem* parent) : QGraphicsItem(parent) {}&lt;br /&gt;LineItem::~LineItem() {}&lt;br /&gt;void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {}&lt;br /&gt;QRectF LineItem::boundingRect() const {&lt;br /&gt; return QRectF();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"CustomScene.h" file contains derived QGraphicsScene class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QGraphicsScene&amp;gt;&lt;br /&gt;class CustomScene : public QGraphicsScene {&lt;br /&gt;public :&lt;br /&gt; CustomScene(QObject * parent = 0);&lt;br /&gt; ~CustomScene();&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"CustomScene.cpp" file contains implementation for derived QGraphicsScene class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "CustomScene.h"&lt;br /&gt;CustomScene::CustomScene(QObject * parent) : QGraphicsScene(parent) {}&lt;br /&gt;CustomScene::~CustomScene() {}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"CustomMainWindow.h" file contains definition for derived QMainWindow class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;class CustomScene;&lt;br /&gt;class CustomMainWindow : public QMainWindow {&lt;br /&gt;public:&lt;br /&gt; CustomMainWindow(QWidget *parent = 0);&lt;br /&gt; ~CustomMainWindow();&lt;br /&gt; void displayItemType();&lt;br /&gt; void addItemsToGraphicsScene();&lt;br /&gt;private:&lt;br /&gt; CustomScene* customScene;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"CustomMainWindow.cpp" file contains implementation for derived QMainWindow class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;#include "CustomMainWindow.h"&lt;br /&gt;#include "CustomScene.h"&lt;br /&gt;#include "CustomGraphicsItems.h"&lt;br /&gt;CustomMainWindow :: CustomMainWindow(QWidget *parent) {&lt;br /&gt; customScene = new CustomScene(this);&lt;br /&gt; addItemsToGraphicsScene();&lt;br /&gt; displayItemType();&lt;br /&gt;}&lt;br /&gt;void CustomMainWindow :: addItemsToGraphicsScene() { &lt;br /&gt; TextItem* textItem = new TextItem();&lt;br /&gt; customScene-&gt;addItem(textItem);&lt;br /&gt; LineItem* lineItem = new LineItem();&lt;br /&gt; customScene-&gt;addItem(lineItem);&lt;br /&gt;}&lt;br /&gt;void CustomMainWindow :: displayItemType() {&lt;br /&gt; QList&amp;lt;QGraphicsItem*&amp;gt; itemList = customScene-&amp;gt;items();&lt;br /&gt; for(int i=0; i&amp;lt;itemList.size(); i++){&lt;br /&gt;  if(itemList[i]-&amp;gt;type() == TextItem::Type )&lt;br /&gt;   qDebug() &amp;lt;&amp;lt; "I am TextItem";&lt;br /&gt;  else if(itemList[i]-&amp;gt;type() == LineItem::Type)&lt;br /&gt;   qDebug() &amp;lt;&amp;lt; "I am LineItem";&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;CustomMainWindow :: ~CustomMainWindow() {}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;"Main.cpp" file contains an instance of CustomMainWindow class. CustomScene is the container for the TextItem and LineItem instances and it is initialized in the CustomMainWindow constructor. addItemsToGraphicsScene() method of CustomMainWindow adds TextItem and LineItem instances to the CustomScene.&lt;br /&gt;Types of custom QGraphicsItem instances are checked in displayItemType() method of CustomMainWindow class.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;#include "CustomMainWindow.h"&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt; QApplication app(argc, argv);&lt;br /&gt;  CustomMainWindow* cm = new CustomMainWindow;&lt;br /&gt;  delete cm;&lt;br /&gt; return app.exec();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Tested with MSVS2008 and QT4.6.0&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/kbJRJkEqdpg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/kbJRJkEqdpg/type-of-custom-qgraphicsitem-on.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/10/type-of-custom-qgraphicsitem-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-2811618906324620281</guid><pubDate>Tue, 28 Sep 2010 21:13:00 +0000</pubDate><atom:updated>2010-09-29T00:19:13.163+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">QVariant</category><category domain="http://www.blogger.com/atom/ns#">QDebug</category><category domain="http://www.blogger.com/atom/ns#">C++</category><category domain="http://www.blogger.com/atom/ns#">QString</category><title>Convert int to QString</title><description>Qt's QVariant helps to convert an integer value to a QString. toString() method of QVariant returns the variant as a QString, if the variant has type() Int.&lt;br /&gt;Also QString's number(long x) method returns a string equivalent of the number x.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include &amp;lt;QVariant&amp;gt;&lt;br /&gt;#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;int main() {&lt;br /&gt;    // use QVariant&lt;br /&gt;    int x = 12;&lt;br /&gt;    QVariant var(x);&lt;br /&gt;    QString stringValue = var.toString();&lt;br /&gt;    qDebug() &lt;&lt; "String to print-1 :"+stringValue;&lt;br /&gt;    //use QString::number(long n, int base = 10)&lt;br /&gt;    QString stringValue2 = QString::number(x);&lt;br /&gt;    qDebug() &lt;&lt; "String to print-2 :"+ stringValue2;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Output produces :&lt;br /&gt;"String to print-1 :12" &lt;br /&gt;"String to print-2 :12"&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/Gmi9I5FQzvQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/Gmi9I5FQzvQ/convert-int-to-qstring.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/09/convert-int-to-qstring.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-6742453380621203619</guid><pubDate>Sun, 26 Sep 2010 20:57:00 +0000</pubDate><atom:updated>2010-09-27T00:12:31.534+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C++</category><title>error: ‘cout’ was not declared in this scope</title><description>When using cout and cin for standard output and standard input purposes without "using directive", compiler generates an error message about undeclared cout and cin. In order to get rid of this error message, it is required to add "using namespace std" using directive at a new line.&lt;br /&gt;App.cpp file&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "App.h"&lt;br /&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;void App::HelloWorld(){&lt;br /&gt;&lt;br /&gt;    cout &lt;&lt; "Hello World";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In addition to #include &amp;lt;iostream&amp;gt; preprocessor directive, insertion of "using namespace std" helps to compile successfully.&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/_SlIp1uM54g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/_SlIp1uM54g/error-cout-was-not-declared-in-this.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/09/error-cout-was-not-declared-in-this.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-5786075807932310767</guid><pubDate>Tue, 13 Jul 2010 10:33:00 +0000</pubDate><atom:updated>2010-07-13T13:46:29.168+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C++</category><title>Forward declaration vs #include directives</title><description>Using forward declaration of C++ classes in header files decreases total compilation time of the application and lowers dependencies. This also makes application easier to modify. It is suggested that when it is necessary to use #include directives, use it. But also avoid usage of unnecessary #include directives and replace them with forward declaration in the header file. Some basic rules that I obey most of the time when using #include directives and forward declarations are as follows:&lt;br /&gt;#include directive :&lt;br /&gt;- Use in both .h header file and implementation file&lt;br /&gt;- Base classes are introduced by using include directives&lt;br /&gt;&lt;br /&gt;forward declaration :&lt;br /&gt;- Use in .h header file &lt;br /&gt;- Pointer return values and method parameters can be forward declared&lt;br /&gt;&lt;br /&gt;Sample.h file :&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;//include directive for base class&lt;br /&gt;#include "BaseItemEntity.h"&lt;br /&gt;//forward declaration for method parameters and return values&lt;br /&gt;class QString;&lt;br /&gt;class Item;&lt;br /&gt;class ItemBody : public BaseItemEntity&lt;br /&gt;{ &lt;br /&gt;public:&lt;br /&gt; QString getItemID();&lt;br /&gt; Item* getItemByName(QString&amp;);&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Sample.cpp file :&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "Sample.h"&lt;br /&gt;#include "Item.h"&lt;br /&gt;&lt;br /&gt;QString ItemBody::getItemID()&lt;br /&gt;{&lt;br /&gt; return QString();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Item* ItemBody::getItemByName( QString&amp; name)&lt;br /&gt;{&lt;br /&gt; Item* item = new Item(name);&lt;br /&gt; return item;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;There is also a useful c++ coding guide that is giving clues for header file dependencies at &lt;a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Header_File_Dependencies"&gt;this link&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/CwS70z7iscA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/CwS70z7iscA/forward-declaration-vs-include.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/07/forward-declaration-vs-include.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-1501117156705190909</guid><pubDate>Fri, 09 Jul 2010 08:32:00 +0000</pubDate><atom:updated>2010-07-09T11:40:20.178+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>static const QString</title><description>Java allows to define constant Strings as&lt;br /&gt;public final static String SIZE = "size";&lt;br /&gt;in your .java files.&lt;br /&gt;&lt;br /&gt;To define static const QString members for a class in c++ environment,&lt;br /&gt;put your static const QString member into related .h file.&lt;br /&gt;Constants.h&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;class QString;&lt;br /&gt;class Constants{&lt;br /&gt;public:&lt;br /&gt; static const QString xmlBaseFolderPath;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Add related initialization of the static member into .cpp file.&lt;br /&gt;Constants.cpp&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;#include "Constants.h"&lt;br /&gt;#include &amp;lt;QString&amp;gt;&lt;br /&gt;const QString Constants::xmlBaseFolderPath = "C:\\XML";&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/cMgMmKTMGu4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/cMgMmKTMGu4/static-const-qstring.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/07/static-const-qstring.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8875168824650027631</guid><pubDate>Wed, 30 Jun 2010 07:43:00 +0000</pubDate><atom:updated>2010-06-30T10:51:06.977+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Qt</category><title>Get list of XML files from specified directory. QStringList,QDir,QRegExp</title><description>QStringList can be used to store the list of names of xml files which are in a directory. Following method returns the list of names of files matching the regular expression.&lt;br /&gt;&lt;pre class="Java" name="code"&gt;&lt;br /&gt;QStringList XMLReader::getListOfFiltersFromDirectory()&lt;br /&gt;{&lt;br /&gt;    QDir directory = QDir("C:\\filters");&lt;br /&gt;    QStringList listOfFilters = directory.entryList(QDir::Files | QDir::NoSymLinks);&lt;br /&gt;    QRegExp rx("*.xml");&lt;br /&gt;    rx.setPatternSyntax(QRegExp::Wildcard);&lt;br /&gt;    listOfFilters = listOfFilters.filter(rx);&lt;br /&gt;    return listOfFilters;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/5l-s1nl5L8I" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/5l-s1nl5L8I/get-list-of-xml-files-from-specified.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/06/get-list-of-xml-files-from-specified.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-4105206583464549054</guid><pubDate>Sat, 17 Apr 2010 20:29:00 +0000</pubDate><atom:updated>2010-04-17T23:56:01.189+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ruby on Rails</category><category domain="http://www.blogger.com/atom/ns#">Ubuntu</category><title>Installing Fast Debugger for NetBeans 6.8 on Ubuntu 9.10</title><description>NetBeans IDE enables &lt;a href="http://rubyonrails.org/"&gt;RoR&lt;/a&gt; developers to set break points in specific parts of source files. It is time consuming to use print statements to trace application development process. Because Fast Debugger uses native C extensions, gcc and some other extra packages need to be installed on your Ubuntu 9.10:&lt;br /&gt;&lt;br /&gt;$ sudo apt-get install build-essential autoconf&lt;br /&gt;&lt;br /&gt;Above command installed the following extra packages :&lt;br /&gt;automake autotools-dev dpkg-dev fakeroot g++ g++-4.4 libstdc++6-4.4-dev m4&lt;br /&gt;patch&lt;br /&gt;&lt;br /&gt;Now you need to install ruby1.8-dev package to compile any native extensions.&lt;br /&gt;&lt;br /&gt;$ sudo apt-get install ruby1.8-dev&lt;br /&gt;&lt;br /&gt;Above command installed ruby1.8-dev package.&lt;br /&gt;Now the ruby-debug-ide gem should build successfully.&lt;br /&gt;&lt;br /&gt;$ gem install ruby-debug-ide&lt;br /&gt;Building native extensions.  This could take a while...&lt;br /&gt;Successfully installed ruby-debug-ide-0.4.9&lt;br /&gt;1 gem installed&lt;br /&gt;Installing ri documentation for ruby-debug-ide-0.4.9...&lt;br /&gt;Installing RDoc documentation for ruby-debug-ide-0.4.9...&lt;br /&gt;&lt;br /&gt;NetBeans automatically detected Fast Debugger.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_QXYYFD4D0S0/S8obD_zq1oI/AAAAAAAAACU/KVJsfnPPIeY/s1600/netbeans_fast_debugger.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 165px;" src="http://2.bp.blogspot.com/_QXYYFD4D0S0/S8obD_zq1oI/AAAAAAAAACU/KVJsfnPPIeY/s320/netbeans_fast_debugger.png" alt="" id="BLOGGER_PHOTO_ID_5461207253621855874" border="0" /&gt;&lt;/a&gt;$ gem list&lt;br /&gt;&lt;br /&gt;*** LOCAL GEMS ***&lt;br /&gt;&lt;br /&gt;actionmailer (2.3.4, 2.3.2)&lt;br /&gt;actionpack (2.3.4, 2.3.2)&lt;br /&gt;activerecord (2.3.4, 2.3.2)&lt;br /&gt;activeresource (2.3.4, 2.3.2)&lt;br /&gt;activesupport (2.3.4, 2.3.2)&lt;br /&gt;linecache (0.43)&lt;br /&gt;rack (1.0.1)&lt;br /&gt;rails (2.3.4, 2.3.2)&lt;br /&gt;rake (0.8.7)&lt;br /&gt;ruby-debug-base (0.10.3)&lt;br /&gt;ruby-debug-ide (0.4.9)&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/_ThVPnSX1GM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/_ThVPnSX1GM/installing-fast-debugger-for-netbeans.html</link><author>noreply@blogger.com (Tufan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_QXYYFD4D0S0/S8obD_zq1oI/AAAAAAAAACU/KVJsfnPPIeY/s72-c/netbeans_fast_debugger.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2010/04/installing-fast-debugger-for-netbeans.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-6545870274746955355</guid><pubDate>Thu, 31 Dec 2009 01:21:00 +0000</pubDate><atom:updated>2009-12-31T03:26:04.543+02:00</atom:updated><title>Coupling and Cohesion</title><description>Time spent on software design process takes the most significant part of the software development life cycle. Taken design decision affects the whole product positively or negatively so at this point, coupling and cohesion come into play.&lt;br /&gt;  Coupling is defined as a measure of intermodule connectivity. There are different forms of coupling such as data,stamp,control and common-environment coupling.&lt;br /&gt;  Cohesion helps to determine how functionally the intramodule components are related. Principal forms of cohesion are listed as functional, sequential, communicational, procedural, temporal, logical and coincidental.&lt;br /&gt;  General design approach includes generating highly cohesive and loosely coupled modules. Highly cohesive modules contain logically related operations together into the same structure and that helps to define responsibility at a specific location. Designing loosely coupled modules decreases dependencies to other modules so a small change in one dependent module does not break other parts.&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/h6YItEaFeak" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/h6YItEaFeak/coupling-and-cohesion.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2009/12/coupling-and-cohesion.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-8403066787907582099</guid><pubDate>Mon, 23 Nov 2009 21:34:00 +0000</pubDate><atom:updated>2010-04-17T23:41:45.933+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Ubuntu</category><title>Set JAVA_HOME and PATH on ubuntu 9.10</title><description>Instead of installing JDK from synaptic package manager, you can manually download JDK 6 Update 17 from &lt;a href="http://java.sun.com/javase/downloads/index.jsp"&gt;http://java.sun.com/javase/downloads/index.jsp&lt;/a&gt;. After downloading "jdk-6u17-linux-i586.bin", make it executable by changing its mode and run to install by issuing following commands.&lt;br /&gt;&lt;br /&gt;$ chmod 777 jdk-6u17-linux-i586.bin&lt;br /&gt;$ ./java_ee_sdk-5_08-jdk-6u17-linux.bin&lt;br /&gt;&lt;br /&gt;After that point edit your /etc/profile file to add lines below:&lt;br /&gt;$ sudo gedit /etc/profile&lt;br /&gt;&lt;br /&gt;PATH=(yourJDKInstallationFolder)/bin:${PATH}&lt;br /&gt;export PATH&lt;br /&gt;JAVA_HOME=(yourJDKInstallationFolder)&lt;br /&gt;export JAVA_HOME&lt;br /&gt;&lt;br /&gt;Save /etc/profile and logout. To test your JAVA_HOME location and installed java version type from the console:&lt;br /&gt;$ java -version&lt;br /&gt;&lt;br /&gt;$ echo $JAVA_HOME&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/gpXtSasYlhk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/gpXtSasYlhk/set-javahome-and-path-in-ubuntu-910.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2009/11/set-javahome-and-path-in-ubuntu-910.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1629739459234463496.post-1806974907679728131</guid><pubDate>Fri, 09 Oct 2009 19:37:00 +0000</pubDate><atom:updated>2009-10-09T22:56:50.406+03:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Ubuntu</category><title>Shutdown Remote Ubuntu Machine</title><description>SSH protocol is used to exchange data between two networked devices using a secure channel. Ubuntu server machines with ssh installed on them can be reached from other computers on the network. Ubuntu's synaptic package manager easily installs ssh for your server machine. In order to reach remote ubuntu server machines with ssh installed on them, type the following command from command line of the client machine:&lt;br /&gt;$ ssh remoteUserName@remoteMachineIPAddress&lt;br /&gt;replace remoteUserName and remoteMachineIPAddress with appropriate values. Then you will see that it is asking for adding to the list of known hosts. write 'yes' for confirmation. Then type following from the console window and press enter, the remote machine will shutdown.&lt;br /&gt;$ sudo shutdown -h now&lt;img src="http://feeds.feedburner.com/~r/blogspot/QFhJrM/~4/JGBWCV4FFdQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/QFhJrM/~3/JGBWCV4FFdQ/shutdown-remote-ubuntu-machine.html</link><author>noreply@blogger.com (Tufan)</author><thr:total>0</thr:total><feedburner:origLink>http://tufangorel.blogspot.com/2009/10/shutdown-remote-ubuntu-machine.html</feedburner:origLink></item></channel></rss>
