Oct

13

Using QPainter to do a Test Resistor Application

By flavio

Like all Eletrical Engineer students thats frequents the laboratory class rooms, i needed to keep in my  mind the color code to know the  resistance of resistors. The picture below show you this code:

Then , i build a Qt application to solution my problem using the QPainter class.

The QWidget contains a method called paintEvent(QPaintEvent *event) to receive paint events passed like event parameter which can be reimplemented in a subclass . The paint event is a request to repaintall or part of widget . In this post we will do it , that is , repaint  part of widget .

Drawing :

At Start, i created a  brawn QLinearGradient  to use at QPainter object background:

void QtResistor::paintEvent(QPaintEvent * /* event */)
{
    QLinearGradient gradient(30,280,520,400);
    gradient.setSpread(QGradient::ReflectSpread);
    gradient.setColorAt(0.0,QColor(255,166,88,255)); //clean brawn
    gradient.setColorAt(1.0,QColor(134,87,46,255));  //dark brawn

After that ,  i created a QPainter and i set the pen and the brush  using the gradient created above :

    painter = new QPainter(this);
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->setPen(QPen(gradient,2));
    painter->setBrush(QBrush(gradient));

In this step i used the method drawPie to draw a pie defined into a rectangle and two angles : the start angle and finish angle.In this case the start is 30 degrees and finish is 300 degrees.

    painter->drawPie(30,280,120,120,30*16,300*16);

The same is done here:

    painter->drawPie(400,280,120,120,210*16,300*16);

Here , i drawed a simple rectangle:

    painter->drawRect(90,310,370,60);

Using the same logic above, when the user clicked at calculate button i drawed more four rectangles
to represent the colors of resistor setted.At this moment too, i calculated the resistance in accordance
with the table showed at starts of this post.

Snapshoots of QtResistor:

S60 3rd FP2:



Maemo N810 :



Downloads:

QtResistor for PC(Linux Ubuntu)
QtResistor for Maemo Devices
QtResistor for Nokia S60 Fp2 Devices Read more »

Oct

1

Creating Debian packages for maemo Qt applications and showing in the application menu

By flavio

Introduction

In this post, I will present how build a .deb package . This is a usual implementation ,but the difference is the Qt Maemo application . Other problem that this post will to solve is how to put the Qt application at Menu of Maemo Device.

.Deb Packages In Brief:

Deb is the extension of the Debian software package format and the most often used name for such binary packages. Like the Deb part of the term Debian. Debian packages are used in distributions based on Debian, such as Ubuntu and others.

Prerequisites:

You need to have libqt4-dev ,Scratchbox and Maemo SDK installed on your Computer and libqt4-dev installed on your Scratchbox ARM target and your Maemo Device . To more informations of ScratchBox Installation click here and to Qt on Maemo click here.

Creating the Application:

You need to create a simple Qt HelloWorld Project on computer. I created a project with two labels how is showed below . Remember of to set the size of QWidget to 720 of Width and 420 of Height because the resolution of Maemo Device.

Copying the Application to Scratchbox:

First , copy the sources files of application to a folder at Scratchbox. In general the address is /scratchbox/users/username/home/username/. I do this:

flavio@flavio-desktop:~/workspace$ cp -r  HelloWorld/ /scratchbox/users/flavio/home/flavio/

Compiling the Application at Scratchbox:

At Start, you need login at Scratchbox:

~$ /scratchbox/login

If necessary select the ARM target using sb-menu . To compile do this :

[sbox-DIABLO_ARMEL: ~] > cd HelloWorld
[sbox-DIABLO_ARMEL: ~/HelloWorld] > qmake
[sbox-DIABLO_ARMEL: ~/HelloWorld] > make

Creating the Tree of Debian Package:

After that , you need to create the following folders:

[sbox-DIABLO_ARMEL: ~/HelloWorld] cd ..
[sbox-DIABLO_ARMEL: ~] > mkdir HelloWorldApplication
[sbox-DIABLO_ARMEL: ~] > mkdir HelloWorldApplication/DEBIAN

You’ll need to create a control file for your package using a simple text edit. In this post I use the Vi.

[sbox-DIABLO_ARMEL: ~] > vi  HelloWorldApplication/DEBIAN/control

In this step we’ll look at what each field in the control file means and what kind of information you need to provide The syntax for the control fields is very simple: the name of the field, followed by a colon, and then the body or value of the field.

Package: HelloWorld
Priority: optional
Version: 1.0
Architecture: all
Maintainer: Flavio Fabricio <flaviofabricio@gmail.com>
Depends: libqt4-dev
Description: This is a HelloWorld Application

Returns to HelloWorld Application directory and create the folders below:

[sbox-DIABLO_ARMEL: ~] > cd  HelloWorldApplication/
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication] > mkdir usr

Creating the /usr subdirectories:

[sbox-DIABLO_ARMEL: ~/HelloWorldApplication] > cd usr/
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr] > mkdir bin
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr] > mkdir lib
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr] > mkdir share

Creating the /share subdirectories:

[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr] > cd share/
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr/share] > mkdir applications
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr/share] > mkdir pixmaps

Creating the hildon subdirectory that is the folder where is the .desktop files :

[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr/share] > cd applications
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr/share/applications] > mkdir hildon

Creating the file thats put the Application on Maemo Menu:

You’ll need to create too, a .desktop file that the Maemo uses to put application at Menu.

[sbox-DIABLO_ARMEL: cd /HelloWorldApplication/usr/share/applications/hildon
[sbox-DIABLO_ARMEL: ~/HelloWorldApplication/usr/share/applications/hildon]>vi helloworld.desktop

Here we’ll to add the address of executable file , image icon file , etc…

[Desktop Entry]
Categories=Qt;
Encoding=UTF-8
Version=0.1
Type=Application
Name=Qt HelloWorld
Exec=/usr/bin/HelloWorld
Icon=helloworld

Copying the Application Compiled to Deb Tree:

[sbox-DIABLO_ARMEL: ~] > cd HelloWorld
[sbox-DIABLO_ARMEL: ~/HelloWorld] > ls
HelloWorld     helloworld.cpp  main.cpp       helloworld.png
HelloWorld.pro helloworld.h    helloworld.ui  ui_helloworld.h

In this step, you will to copy the executable file to /usr/bin folder. This executable is called by helloworld.desktop at line Exec=/usr/bin/HelloWorld on the file described above.

[sbox-DIABLO_ARMEL: ~/HelloWorld] > cp helloworld ../HelloWorldApplication/usr/bin/

Now, you will to copy the sources files to /usr/lib folder.This is Recomended , but not required.

[sbox-DIABLO_ARMEL: ~/HelloWorld] > cp HelloWorld.pro ../HelloWorldApplication/usr/lib/
[sbox-DIABLO_ARMEL: ~/HelloWorld] >helloworld.cpp ../HelloWorldApplication/usr/lib/
[sbox-DIABLO_ARMEL: ~/HelloWorld] >helloworld.h ../HelloWorldApplication/usr/lib/
[sbox-DIABLO_ARMEL: ~/HelloWorld] >helloworld.ui ../HelloWorldApplication/usr/lib/
[sbox-DIABLO_ARMEL: ~/HelloWorld] >main.cpp ../HelloWorldApplication/usr/lib/

You will need of a picture to use like Icon. You can search some image at the Google Images.In this case I renamed the picture to helloworld.png.This image is called by helloworld.desktop at line Icon=helloworld on the file described above and sended to /usr/share/pixmaps/ folder.

[sbox-DIABLO_ARMEL: ~/HelloWorld] > cp helloworld.png ../HelloWorldApplication/usr/share/pixmaps/

Creating the Deb Package:

[sbox-DIABLO_ARMEL: ~/HelloWorld] > cd ..
[sbox-DIABLO_ARMEL: ~] > dpkg-deb -b HelloWorldApplication

Sending the .Deb Package to Maemo Device:

I used the Scp command with the IP address of device. The IP address of device is searched at Settings->Connection Manager , after that , click at Connection Manager at left-Up-Corner->internet connection->IP address.

[sbox-DIABLO_ARMEL: ~/HelloWorld] > scp HelloWorldApplication.deb root@10.0.0.13:/home/

Installing the Deb Package at Maemo Device:

Open a new terminal and do this:

ssh root@10.0.0.13

enter with the password of Maemo Device

root@10.0.0.13's password:
Nokia-N810-43-7:~# cd ..
Nokia-N810-43-7:/# cd /home/
Nokia-N810-43-7:/home# dpkg -i HelloWorldApplication.deb

Ok. The application is installed at Maemo Device.

You will need to click at Extras Menu and you will can see the HelloWorld Aplication: Fine.

This post is avaiable too at Wiki Forum Nokia . Click here to see.

Sep

5

How to do a SOAP webservice request using QtSOAP

By arthurdesribeiro

To do a SOAP webservice request using QtSOAP, is simple, the two main objects that you’re going to need from QtSOAP area a QtSoapHttpTransport, that in this example it’s going to be created in the constructor and a QtSoapMessage, that you can see it use later.
In this example the SOAP client call a method called “sum” that sum two numbers that are passed as parameters.

First of all let’s implement the client.h file:

#include <QDebug>
#include <qtsoap.h>

class Client : public QObject
{
    Q_OBJECT

    public:

        QtSoapHttpTransport http;
        int number1;
        int number2;

        Client(int number1, int number2, QObject *parent = 0);
        void soma();

    private slots:
        void getResponse();
};

#endif

As we could see the numbers that are going to be in the method parameters are passed in constructor of Client class.

Now implement the client.cpp

#include "client.h"

Client::Client(int number1, int number2, QObject *parent) : QObject(parent)
{
    this->number1 = number1;
    this->number2 = number2;
    http.setHost(host, port);
    // Or use just http.setHost(host)
    connect(&http, SIGNAL(responseReady()), this, SLOT(getResponse()));

}

void Client::sum()
{
    QtSoapMessage request;
    request.setMethod("sum");
    request.addMethodArgument("number1", "", number1);
    request.addMethodArgument("number2", "", number2);
    qDebug("sum of %i and %i...", number1, number2);
    http.submitRequest(request, "/soma");
}

void Client::getResponse()
{
    const QtSoapMessage &message = http.getResponse();
    if (message.isFault()) {
        qDebug("Error: %s", qPrintable(message.faultString().toString()));
    }
    qDebug()<< message.returnValue().toString();
}

In the constructor of Client class the two numbers are passed as parameter and the QtSoapHttpTransport host is set.

The sum method is the most important one, first of all you have to create the request message, that contains the method that will be called and the parameters of it. After the creation of message just submit the request to QtSoapHttpTransport host in the right path. The getResponse slot is very important, when the QtSoapHttpTransport receives the response a signal is emitted and enters in this slot, where the response message is going to be shown.

After implementing client.h and client.cpp you just have to implement the main.cpp that is gonna use this functions and it’s done.

Sep

4

How to serialize data using Qt

By caionobrega

Qt provides two classes for serialization, DataStream class to serialization of binary data and QTextStream to “parsing” input stream(reading and writing text). QDataStream class can be used to write portables files (i.e., a data stream written under Windows can be read by other running GNU/Linux or Solaris).

Thus, there are situations that serialization of binary data are very useful to us, for example, create a dictionary like a configuration file. In our example, we write, update and read a QHash(our dictionary).See the list of data types which can be serialized here

#include <QtCore>
#include <QApplication>
#include <QHash>
#include <QFile>
#include <QDataStream>

#define PATH "./file.dat"

int main()
{

//create a dictionary
QHash<QString,QString> dict;
dict["project.owner"] = “owner”;
dict["project.version"] = “0.10.0″;

QFile file(PATH);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);   // write the data
out << dict;
file.close();

//setting new a value
dict["project.owner"] = “new”;

//update the dictionary
file.open(QIODevice::ReadOnly);
QDataStream in(&file);   // read the data serialized from the file
in >> dict;

qDebug() << “value: ” << dict.value(”project.owner”);
return 0;
}

Sep

4

How to create a simple webservice using qt and libqxt.

By andrerag

LibQxt adds some great functionality to the qt toolkit. One of them is a simple framework for building webservers and services. So here is a simple webservice that adds two numbers and returns the result back to who ever is sending the request.
Obs: the complete source code is available for download below.

First we create our service that will add the numbers and return the result. To do this we extend QxtWebServiceDirectory and reimplement the “indexRequested()” function so we can parse the message and get the parameters.

#include "xmlparser.h"

#define DEFAULT_MESSAGE "<h1>RUN AWAY!</h1>"

class WebService : public QxtWebServiceDirectory {

Q_OBJECT

public:
    WebService(QxtAbstractWebSessionManager * sm , QObject * parent = 0);
    virtual ~WebService();

 protected:
    void indexRequested (QxtWebRequestEvent *event);

private:
    XmlParser *parser;
    QString buildResponse(QString sum, QString actionName);
};

The xml parser is implemented using the qt library, however, the focus here is how to create the webservice.

indexRequested() is called whenever someone sends something to the index url of the service. So if we create a service called “add” and someone sends a SOAP request to “http://SOMEIP:PORT/add/”, indexRequested() will be called. indexRequested() receives a QxtWebRequestEvent*, which is an object that contains all the request information sent by the client. It contains the request headers, session Id, request Id and the message itself.

Below is the code for indexRequested() and buildResponse(). buildResponse() builds the response(duh!) using the SOAP protocol, so the client can understand what is being sent back.

void WebService::indexRequested(QxtWebRequestEvent *event)
{
    qDebug() << "Request Headers: ";

    QHash::const_iterator i = event->headers.constBegin();

     while (i != event->headers.constEnd()) {
         qDebug() << i.key() << ": " << i.value();
         ++i;
     }

    if (event->method.compare("POST")==0) {
        QxtWebContent *myContent = event->content;
        qDebug() << "Bytes to read: " << myContent->unreadBytes();
        myContent->waitForAllContent();
        QByteArray requestContent = myContent->readAll();

        qDebug() << "Content: ";
        qDebug() << requestContent;
        parser->parseSOAP(requestContent);

        QString num1 = parser->getNumber1();
        QString num2 = parser->getNumber2();
        QString sum;

        if (num1!="" && num2!="") {
            sum.setNum(num1.toInt()+num2.toInt());
            QString bodyMessage = buildResponse(sum,"add");
            qDebug() << bodyMessage;
            postEvent(newQxtWebPageEvent(event->sessionID,
                                         event->requestID,
                                         bodyMessage.toUtf8()));
        } else {
            QString errorXml = buildResponse("0","add");
            postEvent(new QxtWebPageEvent(event->sessionID,
                                          event->requestID,
                                          errorXml.toUtf8()));
        }
    } else if (event->method.compare("GET")==0) {
        postEvent(new QxtWebPageEvent(event->sessionID,
                                      event->requestID,
                                      DEFAULT_MESSAGE));
    }
}

QString WebService::buildResponse(QString sum, QString actionName)
{
    QString body;
    body.append("<?xml version=\"1.0\"?>\r\n");
    body.append("<s:Envelope
                 xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"
                 s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
                 \r\n");
    body.append("<s:Body>\r\n");
    body.append("<u:"+actionName+"Response
                 xmlns:u=\"urn:schemas-upnp-org:service:somador:1\">
                 \r\n");
    body.append("<"+actionName+">"+sum+"</"+actionName+">\r\n");
    body.append("</u:"+actionName+"Response>\r\n");
    body.append("</s:Body>\r\n");
    body.append("</s:Envelope>\r\n");
    return body;
}

We now create a webserver by extending QxtHttpSessionManager and reimplementing the “incomingRequest()” function, so we can see if someone is requesting something.

#include "webservice.h"

class WebServer : public QxtHttpSessionManager {

Q_OBJECT

public:
    WebServer(const QHostAddress &host , quint16 port);
    virtual ~WebServer();

    void addService(QString uri,WebService *newService);

signals:
    void postReceived(QByteArray content);

protected:
    void incomingRequest(quint32 requestID,
                         const QHttpRequestHeader & header,
                         QxtWebContent *deviceContent);

private:
    WebService *rootService;
};

WebServer::WebServer(const QHostAddress &host,quint16 port)
{
    QxtHttpSessionManager(this);
    rootService = new WebService(this,this);
    setPort(port);
    setListenInterface(host);
    setConnector(HttpServer);
    setStaticContentService(rootService);

    qDebug() << "WebServer Started!";
}

WebServer::~WebServer()
{
    delete rootService;
}

void WebServer::incomingRequest(quint32 requestID,
                                const QHttpRequestHeader & header,
                                QxtWebContent *deviceContent)
{
    QxtHttpSessionManager::incomingRequest(requestID, header, deviceContent);
    qDebug() << "Request: "<< requestID;
    qDebug() << "Method: " << header.method();
    qDebug() << "URI: " << header.path();
}

void WebServer::addService(QString uri,WebService *newService)
{
    rootService->addService(uri,newService);
}

Then we simply create a WebServer and a WebService in our main application, add the webservice into the webserver and call “start()”.

    WebServer *myWebServer = new WebServer(QHostAddress("192.168.1.152"),12345);
    WebService *sum = new WebService(myWebServer,0);

    myWebServer->addService("add",sum);
    myWebServer->start();

Sep

4

How to do colored logging using QtDebug

By andre.dieb

For doing colored logging using QtDebug, you need to install a custom message handler (a sink for all qDebug(), qWarn(), qCritical(), qFatal() log messages). This can be done using the qInstallMsgHandler(handler) function, as follows. Here we also define color macros and a macro for formatting our message to “<time> <level> <message>”.

#include <QtGlobal>
#include <QTime>
#include <iostream>

#define COLOR_DEBUG "\033[32;1m"
#define COLOR_WARN "\033[33;1m"
#define COLOR_CRITICAL "\033[31;1m"
#define COLOR_FATAL "\033[33;1m"
#define COLOR_RESET "\033[0m"

#define LOG_WRITE(OUTPUT, COLOR, LEVEL, MSG) OUTPUT << COLOR << \
QTime::currentTime().toString("hhmmsszzz").toStdString() << \
" " LEVEL " " << COLOR_RESET << MSG << "\n"

static void myCustomLogWriter(QtMsgType type, const char *msg) {
    switch (type) {
        case QtWarningMsg:
            LOG_WRITE(std::cout, COLOR_WARN, "WARN", msg);
            break;
        case QtCriticalMsg:
            LOG_WRITE(std::cout, COLOR_CRITICAL, "CRIT", msg);
            break;
        case QtFatalMsg:
            LOG_WRITE(std::cout, COLOR_FATAL, "FATAL", msg);
            break;
        case QtDebugMsg:
            LOG_WRITE(std::cout, COLOR_DEBUG, "DEBUG", msg);
            break;
    }
}

void logInitialize(void) {
    qInstallMsgHandler(myCustomLogWriter);
}

Done that, export logInitialize() and call it on the beginning of your application. Notice that now all your QtDebug-based logging messages show neat colors and timestamps.

Jun

19

How to Read and Write in XML Files with Qt/C++

By flavio

In this post I will show an basic example of  a Qt application which uses QXmlStreamReader and QXmlStreamWriter objects to write and read XML files . I will  also show how to change icon of QPushbutton according to its state (Unchecked or Checked).

WRITING XML:

When we selected the fields with the informations and clicked on FileMenu->SaveAs the function SaveXMLFIle() is called . Then, a dialog will request for to save the filename. Once the  XML is created and is showed on QTextEdit.

void XmlUpnp::SaveXMLFile()
{
  filename = QFileDialog::getSaveFileName(this,
		                               tr("Save Xml"), ".",
		                               tr("Xml files (*.xml)"));

  QFile file(filename);
  file.open(QIODevice::WriteOnly);

  QXmlStreamWriter xmlWriter(&file);
  xmlWriter.setAutoFormatting(true);
  xmlWriter.writeStartDocument();

  xmlWriter.writeStartElement("LAMPS");

  xmlWriter.writeStartElement("LIGHT1");
  xmlWriter.writeTextElement("State", ui.pushButton1->isChecked()?"Off":"On" );
  xmlWriter.writeTextElement("Room",ui.comboBox1->currentText());
  xmlWriter.writeTextElement("Potencial",QString::number(ui.spinBox1->value()));
  xmlWriter.writeEndElement();
   ...
  xmlWriter.writeStartElement("LIGHT4");
  xmlWriter.writeTextElement("State", ui.pushButton4->isChecked()?"Off":"On" );
  xmlWriter.writeTextElement("Room",ui.comboBox4->currentText());
  xmlWriter.writeTextElement("Potencial",QString::number(ui.spinBox4->value()));
  xmlWriter.writeEndElement();
  xmlWriter.writeEndElement();
  xmlWriter.writeEndDocument();

  file.close();
  ShowXmlOnScreen();
  statusBar()->showMessage(tr("Xml Saved"));
}

READING XML:

When we clicked on FileMenu->Open the function OpenXMLofFIle() is called . Is opened a QFileDialog and the file is choosen. After the the XML is showed on QTextEdit and the others fields are filled.

void XmlUpnp::OpenXMLofFile()
{
	ui.textEdit->clear();
	filename = QFileDialog::getOpenFileName(this,
	                               tr("Open Xml"), ".",
	                               tr("Xml files (*.xml)"));

	QFile file(filename);
	if (!file.open(QFile::ReadOnly | QFile::Text))
	{
	    std::cerr << "Error: Cannot read file " << qPrintable(filename)
	     << ": " << qPrintable(file.errorString())
	     << std::endl;
	}
	Rxml.setDevice(&file);
	Rxml.readNext();

	while(!Rxml.atEnd())
	{
		if(Rxml.isStartElement())
		{
			if(Rxml.name() == "LAMPS")
			{
			   READNEXT();
			}
			else if(Rxml.name() == "LIGHT1")
			{
			   ReadLightElement(0);//entra
			}
			else if(Rxml.name() == "LIGHT2")
			{
			   ReadLightElement(1);//entra
			}
			else if(Rxml.name() == "LIGHT3")
			{
			   ReadLightElement(2);//entra
			}
			else if(Rxml.name() == "LIGHT4")
			{
			   ReadLightElement(3);//entra
			}
			else
			{
	   		  Rxml.raiseError(QObject::tr("Not a bookindex file"));
			}
		}
		else
		{
 			READNEXT();
        	}
   }
   file.close();
   if (Rxml.hasError())
  {
          std::cerr << "Error: Failed to parse file "
         << qPrintable(filename) << ": "
         << qPrintable(Rxml.errorString()) << std::endl;
  }
  else if (file.error() != QFile::NoError)
  {
      std::cerr << "Error: Cannot read file " << qPrintable(filename)
               << ": " << qPrintable(file.errorString())
               << std::endl;
  }

  ShowXmlOnScreen();

  statusBar()->showMessage(tr("Xml Opened"));
}

CHANGING ICONS OF BUTTONS:

When the PushButton of the Lamp is clicked, its picture is changed according to state (ON or OFF).On the XmlUpnp class constructor is started two QIcons with two pictures. The first is a Off lamp and the second is a ON Lamp. At the moment of the click on the Button ,the  on_pushButtonX_toggled() function is called changing the picture to according of the Lamp state , (Checked=Off or Unchecked=On).

XmlUpnp::XmlUpnp(QWidget *parent) : QMainWindow(parent)
{

...

icon1.addPixmap(QPixmap(QString::fromUtf8("icons/onlight1.png")),
QIcon::Normal,QIcon::Off);

icon2.addPixmap(QPixmap(QString::fromUtf8("icons/offlight1.png")),
QIcon::Normal,QIcon::Off);

}
void XmlUpnp::on_pushButton1_toggled()
{
	if(ui.pushButton1->isChecked())
	{
		ui.pushButton1->setIcon(icon2);
		labelArray[0]->setText(”OFF”);
	}
	else
	{
		ui.pushButton1->setIcon(icon1);
		labelArray[0]->setText(”ON”);
	}
}

SCREENS:

The start screen of application shows four pushbuttons and for each pushbutton,  a Label with the state of the lamp, a QComboBox with the room where the lamp is , other QComboBox with the lamp potential and a QTextEdit with the XML code.

All fields are clean  waiting the user change the value or open a XML file at FileMenu->Open .Then  the XML file is showed on the QTextEdit and the others fields are filled with the information on the XML opened.

DOWNLOAD CODE:

XMLQT Code

Jun

17

How to get network interface information using Qt

By andrerag

Sometimes it’s usefull to know the ip address from your local network interfaces, especially if you are using mobile or embedded devices, it’s sometimes difficult now and then to get this information going through the settings menu, (i’ve personally struggled to get the ip address off a 5800 xpress music phone), so here is how you do it:

// First create a QNetworkInterface object.

QNetworkInterface interface;

// Then declare a QList using QHostAddress as the list type.

// After this, you can simply use ".allAddresses()" method to get ALL the
// network interface information, easy enough no?

QList<QHostAddress> IpList = interface.allAddresses();

// After that you can display the ip numbers on the console or do whatever you
// want with them.

for (int i = 0; i < IpList.size(); i++)
     cout << "Interface " << i << ":" << IpList.at(i).toString() << endl;

Jun

17

How to fix the “_limits.h” problem using Qt for s60

By andrerag

When compiling software using Qt for s60 or OpenC++, you can come across some problems. One of the very first problems is when you code on some other OS(linux for example) and port your code to windows for compiling and testing on the device. If most of the problems have something to do with the header file “_limits.h”, there is a simple solution. All you have to do is copy the folowing to your .mmp file:

OPTION CW -wchar_t on
MACRO _WCHAR_T_DECLARED

If you are using Qt for S60 and dont know how to add the lines to your mmp file, since when you run qmake, the mmp file is rebuild with the .pro expecifications. then all you have to do is add the following lines to your .pro file:

MMP_RULES += “OPTION CW -wchar_t on”
DEFINES += _WCHAR_T_DECLARED


May

8

How to Develop Qt/C++ S60 Applications on Carbide

By flavio

In this post, I will present all steps To Developing a first Qt/C++ applications for S60 mobile phones . I recorded a full video of all necessary softwares installation that allow the development of mobile phone applications.

Necessary Softwares :

  • Nokia Pc Suite ->Is a software package used to establish an interface between Nokia mobile devices and computers.
  • Carbide C++ ->Is a software development tool for C++ development on Symbian OS. It is used to develop phones that use the OS, as well as applications that run on those phones.
  • Active Perl -> ActivePerl is the industry-standard Perl distribution, available for Windows, Linux, Mac OS X, etc..
  • Java Runtime Environment(JRE)->Is a set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts.
  • S60 Sdk 3rd Edition Fp1 or higher->A software development kit (SDK or “devkit”) is typically a set of development tools that allows a software engineer to create applications for a certain software framework, hardware platform, computer system, video game console, operating system, or similar platform.

(In this Post we Installed Sdk 3rd Edition and Sdk 5rd Edition)

  • OpenC/C++ for S60 *3rd Edition Fp1-> is a development environment from Nokia for the S60 platform.

(Automatically included on SDK 3rd Edition Fp2 and higher)

  • Qt for S60 “Garden”->Qt is a powerful C++ application development framework, which makes it easy for developers to create applications once and then deploy them on any of the Windows, Mac, Linux, Windows CE, Windows Mobile and embedded Linux platforms. With the inclusion of the S60 platform, developers have an additional 80 million* target devices that they can support with their Qt-based applications.

First Video :

Step 1:

Step 2:

  • Before the download and installation of Carbide is necessary a free Registration on Forum Nokia webSite and after Download and Install Nokia Carbide at address: Carbide C++ .

Step 3:

  • At the end of Carbide Installation was showed the link of ActivePerl download . You can use this or go to the address : Active Perl for download and install the carbide.

Step 4:

  • In this step download and install Java Runtime Environment(JRE) on the addres : JRE .

Step 5:

  • The address for the fifth step is SDK 3rd Edition Fp1 and you can download and install the SDK 3rd Edition FP1.

Step 6:

  • The sixth step show you how to install the OpenC/C++ for S60 3rd Edition using the address OPENC/C++ SDK 3RD .

Step 7 :(Optional)

  • The seventh step is Optional because the developer use the Sdk specified for the mobile phone edition . On ForumNokia WebSite is possible view the edition of each mobile Nokia Devices Specifications .For the download and installation of the SDK 5th Edition use SDK 5th Edition .

Second Video :

Step 8 :

  • In this step we will show you how to install the most important tool of this Post : “The Qt Garden” . On the S60 Pre Releases Qt Garden you will get many informations and details about qt installation . The step by step of qt installation is on Step-by-Step Qt Installation .

Step 9 :

  • The ninth step show a important point of qt installation . It’s the fifth step of tutorial step by step above and show you how to extract Qt binaries of Qt Garden directories to SDK directories.

Third Video :

Step 10:

  • This step show you how to adjust the patches of QT to SDK installation . This is on Qt Patches .

Fourth Video :

Step 11:

  • The eleventh step show you all need configurations for the normal use of the Carbide C++.

Step 12 and Step 13:

  • These steps show you finally how to Build a Example Project for S60 Mobile Phone since the 3rd Edition until 5th Edition devices.