<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Improved</title>
	<atom:link href="http://blog.codeimproved.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codeimproved.net</link>
	<description></description>
	<lastBuildDate>Sun, 18 Dec 2011 18:50:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DevDays lessons: how to use a state machine to drive a QML UI</title>
		<link>http://blog.codeimproved.net/2011/12/devdays-lessons-how-to-use-a-state-machine-to-drive-a-qml-ui/</link>
		<comments>http://blog.codeimproved.net/2011/12/devdays-lessons-how-to-use-a-state-machine-to-drive-a-qml-ui/#comments</comments>
		<pubDate>Sun, 18 Dec 2011 18:50:18 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software design]]></category>
		<category><![CDATA[DevDays]]></category>
		<category><![CDATA[QML]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=330</guid>
		<description><![CDATA[One of the more interesting presentations at DevDays 2011 was given by Marius from Cutehacks. After hearing this presentation I had a bit of an epiphany when it comes to state machines. I had been using them in Qt for quite a while, but I was never happy with how they meshed with the rest [...]]]></description>
			<content:encoded><![CDATA[<p>One of the more interesting presentations at DevDays 2011 was given by <a href="http://cutehacks.com/aboutus/">Marius from Cutehacks</a>. After hearing this presentation I had a bit of an epiphany when it comes to state machines. I had been using them in Qt for quite a while, but I was never happy with how they meshed with the rest of the components. Indeed, there was a simpler and clearer way to do it, and that&#8217;s what I&#8217;m going to talk about in this article &#8211; the Cutehacks state machine design and how I used it in a real app.</p>
<h1>The theory</h1>
<p>The actual presentation slides are <a href="http://www.slideshare.net/mariusbu/the-anatomy-of-real-world-apps?player=js">here</a> and they have some sample code if you&#8217;re interested, but off the top of my head, here&#8217;s how Cutehacks does it:</p>
<ol>
<li>First of all, they noticed that implementing a state machine in pure QML was not the best idea. To tell you the truth, I was also surprised when first encountering QML states &#8211; sure they were very flexible, but the result wasn&#8217;t really a formal state machine. In QML you can switch from any state to any other state and even to ones that don&#8217;t exist, because the current state is just a name stored in a string property.</li>
<li>One solution to the above problem is implementing the state machine in C++. Cutehacks inherited their state machine from the QStateMachine class and declared all the states as private members. That state machine had a signal corresponding to each state that shared that state&#8217;s name. e.g: state mFoo matched signal foo() inside the state machine.</li>
<li>Each state had an isActive property that was exposed together with the state to QML. In order to make isActive work, they inherited from QState and reimplemented the onEntry and onExit events to toggle the property.</li>
</ol>
<p>So far we have our own state machine with states and transitions neatly defined in C++ in the constructor, we have signals that can be used to transition between states and each state has an isActive property. How is this connected to QML? Each C++ state was matched with a QML state having the &#8220;when&#8221; property set to &#8220;cppState.isActive&#8221;.</p>
<p>It turns out that in QML you can call the signals of any C++ object that has been exposed to QML! So in the UI files when pressing a button you could say something like cppStateMachine.mainState() and then the mainState() signal of the cppStateMachine C++ object would be called. If the current state had a transition to mainState, then the transition would happen, mainState.isActive would become true and the corresponding QML state for mainState would be entered.</p>
<p>Finally, the entire point is that in the QML state you could then change some random QML properties on entry or even run some JavaScript code.</p>
<h1>The practice</h1>
<p>When coming back from DevDays, I attempted to use this state machine design in a C++/QML app that I was working on. Previously I was using only QML states, but it was reasonably easy to refactor the code to use a C++ state machine in the background. The implementation felt more robust, as I could just take a look in the C++ state machine implementation to see how the app behaved, instead of hunting for the elusive assignments to the &#8220;state&#8221; property. It was also easier to make changes, since the UI changes were well defined in one place now.</p>
<p>Soon after that, I ran into quite a big issue though&#8230; In the app I was working on, transitions were important &#8211; for instance when going from A -&gt; B something was supposed to happen, but when going from C -&gt; B, or even B -&gt; A something different had to happen. My first thought was to use the Transition QML element. After adding a few transitions for testing, I noticed that the Transition animations and code were not being executed.</p>
<p>Immediately I suspected that &#8220;when&#8221; was the problem. If you&#8217;ll remember, state transitions were made in a specific way: each QML state had &#8220;when&#8221; set to the C++ state&#8217;s isActive property. In a C++ transition from A -&gt; B, the QML transitions were A -&gt; &#8220;&#8221;-&gt; B instead of A -&gt; B. The empty string is the default QML state. Since A.isActive became false, the state machine transitioned to the default state automatically. Then it transitioned to B when B.isActive became true.</p>
<p>As one can see QML state machines are quite peculiar&#8230;</p>
<p>The way I solved this was by integrating the C++ state machine more tightly with the QML state machine:</p>
<ol>
<li>I removed the isActive property for the C++ states and the &#8220;when&#8221; property for all QML states.</li>
<li>For each qmlState I set its name to cppState.objectName, which is just the the QState&#8217;s QObject name.
<pre>State {
           name: cppStateMachine.initState.objectName [...]</pre>
</li>
<li>In MyState::onEntered I emitted a signal called enteredWithObjectName(QString) and passed the objectName() to it.
<pre>void MyState::onEntry(QEvent *event)
{
    [...]
    emit enteredWithObjectName(objectName());</pre>
</li>
<li>When setting up the state machine, I connected the enteredWithObjectName for each state to the C++ state machine&#8217;s stateChanged(QString) signal.
<pre>connect(mInit, SIGNAL(enteredWithObjectName(QString)), SIGNAL(stateChanged(QString)));</pre>
</li>
<li>In QML I wrote a signal handler called onStateChanged and in there I set the QML &#8220;state&#8221; property to the name parameter passed to the signal.
<pre>Connections {
        target: cppStateMachine
        onStateChanged: {
            console.debug("changing state to " + objectName);
            rootWindow.state = objectName;
        }
    }</pre>
</li>
</ol>
<p>The end result was that now transitions were done directly from on state to another without going through the default &#8220;&#8221; state. When a QML object called cppStateMachine.mainState(), a C++ state transition happened, the C++ state mainState was entered and it emitted its QObject.objectName. The state machine then passed that on to QML and the QML set the state property to that name, effectively triggering a QML state transition. Since each QML state had the same name as the C++ QState object, it worked.</p>
<p>This implementation allowed for a lot of flexibility with state changes. If some transitions were similar, they could be grouped in a QML Transition with from set to &#8216;*&#8217;(star/any state). If there was a special case, from could be set to specialState.objectName, and the QML transition would only execute for that state, while &#8216;*&#8217; would work for the rest.</p>
<p>The advantage with C++ is that the state machine API is already implemented, but my assumption is that a similar state machine API can be written in JavaScript, so that you could have a pure QML/JS project if that&#8217;s what you want. The important ideas when building such an API are to respect <a href="https://en.wikipedia.org/wiki/Finite-state_machine">the definition of a FSM</a> in your design and to encapsulate operations such as state and transition set up and transition triggers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2011/12/devdays-lessons-how-to-use-a-state-machine-to-drive-a-qml-ui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QsWallet 1.1.8r is available on Ovi</title>
		<link>http://blog.codeimproved.net/2011/04/qswallet-1-1-8r-is-available-on-ovi/</link>
		<comments>http://blog.codeimproved.net/2011/04/qswallet-1-1-8r-is-available-on-ovi/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 06:57:31 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ovi]]></category>
		<category><![CDATA[qswallet]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=306</guid>
		<description><![CDATA[A minor release of QsWallet &#8211; version 1.1.8 &#8211; has just been published on Ovi. New feature highlights: kinetic scrolling ui improvements fixed an account currency selection bug Ovi download link: http://store.ovi.com/content/58959]]></description>
			<content:encoded><![CDATA[<p>A minor release of QsWallet &#8211; version 1.1.8 &#8211; has just been published on Ovi.</p>
<p>New feature highlights:</p>
<ul>
<li>kinetic scrolling</li>
<li>ui improvements</li>
<li>fixed an account currency selection bug</li>
</ul>
<p>Ovi download link:<a href="http://store.ovi.com/content/58959" target="_blank"> http://store.ovi.com/content/58959</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2011/04/qswallet-1-1-8r-is-available-on-ovi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The state of Qt on Symbian</title>
		<link>http://blog.codeimproved.net/2010/12/the-state-of-qt-on-symbian/</link>
		<comments>http://blog.codeimproved.net/2010/12/the-state-of-qt-on-symbian/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 14:59:17 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[Symbian]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=292</guid>
		<description><![CDATA[I&#8217;ve meant to write this for a long time, because there&#8217;s not a lot of information about what it&#8217;s like to use Qt on Symbian. There is the Nokia marketing and there are some short developer testimonials, but the situation in the trenches can be different from what gets out in the news. This blog [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve meant to write this for a long time, because there&#8217;s not a lot of information about what it&#8217;s like to use Qt on Symbian. There is the Nokia marketing and there are some short developer testimonials, but the situation in the trenches can be different from what gets out in the news.</p>
<p>This blog post is structured in a Q&amp;A format. The questions are those that I would have liked to have had an answer to when I started Qt Symbian development + some others that I have found interesting to think about.</p>
<p><strong> Q: How hard is it for a Qt desktop developer to make the transition to mobile? </strong></p>
<p>A: Qt is almost the same on Symbian as on other platforms. The Symbian-specific idioms (e.g the dreaded cleanup stack) are hidden from the programmer, but there are new UI concepts and new .pro statements and options. The Symbian build and deployment processes are notable differences that normally won&#8217;t give you trouble, but when they do give you trouble you will have to interact with the Symbian side.</p>
<p><strong> Q: I have experience with Symbian C++, how does it compare to Qt? </strong></p>
<p>A: Qt is much easier, you can avoid the cleanup stack, two-phase  constructors, descriptors and active objects and the native UI classes. I  have talked to people that did Symbian C++, Android and iOS dev.  According to them, Symbian C++ is ~2x more time-consuming than the other  two, Qt is about the same.</p>
<p><strong> Q: What books / tutorials should I read? </strong></p>
<p>A: Unfortunately, there is no one place where you will find all you need, the info is split between Forum Nokia, the (ex)Symbian Foundation, the Qt bug tracker, the Qt docs and books.</p>
<p>Let&#8217;s discuss them one by one:</p>
<p>* Forum Nokia hosts a Wiki and the Qt for Symbian section of the discussion boards. This is the best place to ask questions, because Qt Symbian devs and other experienced people read the boards. Some Wiki articles are part of the Knowledge base and contain info that&#8217;s not available elsewhere.</p>
<p>* The Symbian foundation websites had quite a few tidbits of info, but AFAIK those aren&#8217;t easily accessible any more because the Symbian Foundation has been merged into Nokia. You had the option of asking more technical Symbian questions on the forums there.</p>
<p>* It&#8217;s useful to browse the bug tracker to look out for Symbian bugs and their potential workarounds. Once again, some of this info is not available elsewhere (like a known bugs document).</p>
<p>* The Qt docs contain Symbian-specific sections that you must read. Some classes/functions contain platform notes.</p>
<p>* The &#8220;Porting to the Symbian platform&#8221; book is useful for a Qt on Symbian newbie since it explains differences between platforms, Symbian stuff such as the security model or PIPS and even contains example ports.</p>
<p><strong>Q: How do I set up my development environment? </strong></p>
<p>A: Just download the latest version of Nokia Qt SDK. There&#8217;s a naming problem here, because there&#8217;s also a &#8220;Qt for Symbian&#8221; download package, and a Qt SDK for [your OS]. You need the &#8220;Nokia&#8221; Qt SDK. Silly, I know, but it has gotten much simpler since the beginning where you had to watch a video to get a dev environment running.</p>
<p>Make sure you use the Qt Creator from the SDK, it has some special Symbian enhancements.</p>
<p><strong> Q: What are the biggest problems that I should expect? </strong></p>
<p>A: The look &amp; feel is not completely adapted to Symbian, and in 4.6.3 there are UI bugs that you have to work around. The Symbian .pro options are not documented enough, and you might have to resort to trial and error.</p>
<p>I think that despite all the available comm channels, Nokia still has a communication problem when it comes to developers. I have gotten good results with the Qt bug tracker and by talking to Nokia devs. On the other hand Ovi store support is only done by e-mail for example and you don&#8217;t get a case number for support inquiries or a case history.</p>
<p><strong> Q: How cross-platform is Symbian Qt? </strong></p>
<p>A: Right now it&#8217;s probably the most cross-platform framework. I have  done Symbian apps that run on Windows or Linux, and this was a major  selling point for me. The UI must be carefully designed and will  probably be different for each platform, but it&#8217;s still Qt and you still  use QWidgets.</p>
<p><strong>Q: What phones should I target?</strong></p>
<p>A: Nokia has a lot of smart phone models on the market and most of them support Qt. The important difference is whether they use touch screens or not. You can and should target all the touch screen devices without much trouble. Check the phone stats report published in the Ovi newsletter for hints on popular phones.</p>
<p>Non-touch phones are a different story, and as far as I&#8217;ve seen there are few Qt apps targeting them. A potential opportunity, but my own experience indicates that Qt is significantly harder to use on those phones. The UI in particular is troublesome.</p>
<p><strong>Q: Is Symbian Qt ready for commercial use? </strong></p>
<p>A: Yes, but there are a few nuissances.</p>
<p>* You have to use a &#8220;Smart installer&#8221; when shipping on Ovi. This installer will download Qt if it&#8217;s not already available on the target devices (a 6-13MB download). The Smart installer isn&#8217;t very user friendly and your Ovi app description must contain a warning that the app might download 13MB of data. Needless to say, the customers can be confused by the message and they can even become upset if it&#8217;s a simple app.</p>
<p>* Ovi only allows Qt 4.6.3 which has some annoying bugs on Symbian. Use the bugtracker to see if anything you need is not working and check for workarounds.</p>
<p><strong>Q: Can I ship software with Qt now? </strong></p>
<p>A: You can ship either on Ovi store, on 3rd party stores or on your  own website. Ovi supports only Qt 4.6.3 at the moment. If you want to  publish outside of Ovi, it is very likely that you will need a Publisher  ID and you will have to sign your app. The ID costs about $200 and  signing costs $10.</p>
<p>Nokia will take care of signing if you publish on Ovi, but you will  not get the signed setup package, it is published directly to the store.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/12/the-state-of-qt-on-symbian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Qt Creator, sln files and pro files</title>
		<link>http://blog.codeimproved.net/2010/12/qt-creator-sln-files-and-pro-files/</link>
		<comments>http://blog.codeimproved.net/2010/12/qt-creator-sln-files-and-pro-files/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 11:36:30 +0000</pubDate>
		<dc:creator>razvanpetru</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[VisualStudio]]></category>

		<guid isPermaLink="false">http://blog.codeimproved.net/?p=287</guid>
		<description><![CDATA[The sln and vcproj file formats can change between Visual Studio versions, so the only reliable way to do conversions is with Visual Studio and the Qt Add-In for Visual Studio. Once the Add-In is installed, open your Qt solution with Visual Studio and select the &#8220;Create basic pro file&#8221; option from the &#8220;Qt&#8221; menu [...]]]></description>
			<content:encoded><![CDATA[<p>The sln and vcproj file formats can change between Visual Studio versions, so the only reliable way to do conversions is with Visual Studio and the <a href="http://qt.nokia.com/downloads/visual-studio-add-in" target="_blank">Qt Add-In</a> for Visual Studio.</p>
<p>Once the Add-In is installed, open your Qt solution with Visual Studio and select the &#8220;Create basic pro file&#8221; option from the &#8220;Qt&#8221; menu item. The Add-In will generate pro and pri files with all the relevant settings from the sln and vcproj files.</p>
<p>If you want to open pro files from Visual Studio instead, just select &#8220;Open Qt pro file&#8221; from the &#8220;Qt&#8221; menu and the sln and vcproj files will be created automatically.</p>
<p>Do expect to make minor adjustments to the generated files, as the conversion is not perfect.</p>
<p>Note: This doesn&#8217;t work with the VS Express edition, since that version doesn&#8217;t support plugins.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codeimproved.net/2010/12/qt-creator-sln-files-and-pro-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: blog.codeimproved.net @ 2012-02-05 19:16:38 -->
