Simon
Qt
WebKit
Posted by Simon
 in Qt, WebKit
 on Friday, November 30, 2007 @ 08:28

It’s been a while since the last update and a few things happened that are worth reporting.

  • George and Adam visited us in Oslo for a week. We’ve spent a fair amount of time discussing all sorts of topics and we have moved our Git repository over to http://code.staikos.net. The new machine setup makes it possible to give contributors push access.
  • Adam did a lot of great cleanup work in the QtWebKit Wiki pages, including instructions on the use of Git with WebKit’s Subversion repository for example
  • We have started reworking the API on the class level. You can follow the work in the shared/api-changes branch. Right now we want to have a toplevel QWebView class that is a QWidget and provides all the convenience to cover most use-cases. Below that we place QWebPage which contains page related functionality like the actions and the history. The page then provides access to the QWebFrame objects, which deal with the per-frame scrollbars and allow rendering into a given QPainter.
  • Thiago integrated the new network access API into Qt and work has started in the shared/network-access branch to port QtWebKit over to use that API. This will completely replace the existing public networking API in QtWebKit when compiled against Qt 4.4. Of course we will keep the old QWebNetworkInterface API around when compiling against Qt 4.3.
girish
Qt
Qtopia
KDE
Styles
Posted by girish
 in Qt, Qtopia, KDE, Styles
 on Tuesday, November 27, 2007 @ 16:37

This feels great. This post is an eight year old dream come true - I have always wanted to write an article titled “… for fun and profit” ever since I read the amazing phrack article :).

Qt Style Sheets makes it possible to style Qt widgets, we all know that. But, what if some user loved this Qt application and would love it even more, if only it had red push buttons (some users have strange fetishes)?

Qt 4.3’s well kept secret
In Qt 4.3, users can customize the style of any application without touching or recompiling the code. All Qt applications can take an external stylesheet using the -stylesheet command line switch. So, create a file called mystyle.qss containing “QPushButton { background: red; }”. Now start, any Qt applications as “qtapp -stylesheet mystyle.qss”. Sweeeet.

Theming Qt
So one can style widgets, but what if one wants to move things around. What if one wants the application to have a completely different layout. We have received many requests for supporting layouting in Qt Style Sheets, but did you know theming Qt applications is already possible?

So let’s see - we need a mechanism for the user to specify the layout. We can probably define our own XML format but it turns out Qt already has one and you use it all the time - .ui files. .ui file is nothing but the user interface described in XML. All we need is a mechanism to load these ui files on the fly.

Enter our hero QUiLoader. QUiLoader reads a ui file and gives you back a QWidget pointer. Ui files can be edited using Qt Designer, so you don’t need to create your own layout tool. In addition, QUiLoader::setWorkingDirectory allows creating ui files with external resources. That said, the main disadvantage is that theming this way requires you to modify your application.

I cooked up a media player that implements the above idea. You can add new themes in the themes/ folder. In addition to a layout(ui) file, the theme can also specify a style sheet. MediaPlayer can load these new themes with no recompilation.

Here’s the Classic theme that has the media controls on the bottom.
Classic Media Player

Here’s the Modern theme that has the media controls on the side.
Modern Media Player

To create a new theme,
* Unpack the source (with git history)
* qmake && make
* cp -R themes/classic themes/mytheme. At this point, mytheme and classic are identical.
* Edit file in mytheme/mediaplayer.ui using Designer
* Edit style sheet in mytheme/mediaplayer.qss using text editor
* Edit icons (play/stop/pause) under mytheme/.
* Notice how media player can support new layouts and styles with no recompilation at all.

Enjoy!

P.S: This is really a guest blog since I don’t work for Trolltech anymore :-) Please contact me at ramakrishnan dot girish at gmail, if you have any questions.

Thiago Macieira
Qt
KDE
WebKit
Internet
Posted by Thiago Macieira
 in Qt, KDE, WebKit, Internet
 on Saturday, November 24, 2007 @ 10:28

As you can probably see from recent blogs, lots of new features are being merged into the mainline Qt (what will become Qt 4.4.0). The latest big one is the Network Access API we’ve been developing for the past few months. It’s in today’s snapshot, so you can try it out already. I’d like to thank Marius Monsen, Prasanth, Lars, Andreas, Simon and everyone else who contributed (even if they just contributed opinions).

It’s also one of the big pieces necessary for WebKit: what’s the use of a browser engine if you can’t download anything off the Internet? And another big new feature: an entirely new HTTP stack, written from the scratch to be fully HTTP/1.1 compatible. At this point in time, we’re throwing random junk and real HTTP replies into it to see how it handles broken servers out there (and broken applications too, like trying to download HTTP off the wrong port).

The design is fairly simple. And if it gives you a sensation of déjà vu, it may be because we designed it to be similar to KIO. And now you’re going to ask me: is it supposed to replace KIO? Well, definitely not, at least not in Qt 4.4: KIO does a lot more than file transfers. It also does file management operations (such as copying, moving, deleting, etc.), which is not part of our design here.

But enough of talking, let’s see some code. The following is a full application that downloads the contents of the first argument:

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    QNetworkAccessManager manager;
    QNetworkReply *reply = manager.get(QUrl::fromEncoded(argv[1]));
    app.connect(reply, SIGNAL(finished()), SLOT(quit()));
    app.exec();
    qDebug() < < reply->readAll();
}

QNetworkAccessManager is the central class in the design. It holds some configuration (proxy, defaults, etc.) and some internal state. It takes one QNetworkRequest object and an operation (based on HTTP operations: get, post, put, head) and returns a QNetworkReply object.

QNetworkRequest is a simple, value-based implicitly-shared class that holds a URL and some meta-data: HTTP headers and extra attributes. It also does parsing of some tricky HTTP headers for you, so you don’t have to worry about getting the HTTP dates right.

Finally, QNetworkReply is an abstract QIODevice-based class. It’s open for reading by the time you get it, which means it will emit readyRead() whenever data is available for reading. Unlike KIO::TransferJob, if you don’t react to the signal, you won’t lose the data.

The next phase now is to make WebKit use this new infrastructure. The API will probably have a simple setManager() function that takes a QNetworkAccessManager object. When it needs more data from the network, it’ll simply call get() there.

We’ve also designed it to be extensible. You’ll be able to write your own QNetworkAccessManager class, that returns your own QNetworkReply objects and/or implements your application’s own network and security policies.

We’re interested in the feedback you can give us. The team and I are available for questions in the qt4-preview-feedback mailing list.

Morten
Qt
Threads
Qt Concurrent
Posted by Morten
 in Qt, Threads, Qt Concurrent
 on Friday, November 23, 2007 @ 13:17

Just a quick update to say that Qt Concurrent has been integrated into Qt/main and is now available in the snapshots. The documentation is available here, end there’s a couple of examples in the examples/qtconcurrent/ directory in the snapshot package. Enjoy!

Bradley T. Hughes
Qt
Labs
Aggregated
 in Qt, Labs, Aggregated
 on Thursday, November 22, 2007 @ 13:54

A couple of years ago (3, to be exact), my girlfriend and I bought a house about 45 minutes outside of Oslo. The little village is just far enough and small enough to not get cable TV. So, that means we have to have satellite. I consider myself a lucky geek, because my tuner runs Linux.
Read the rest of this entry »

Andreas
Qt
KDE
Labs
Graphics View
Graphics Items
Posted by Andreas
 in Qt, KDE, Labs, Graphics View, Graphics Items
 on Thursday, November 22, 2007 @ 11:05

The day has finally arrived. We are proud to announce that we have now integrated our development branch for the Widgets On The Canvas project into Qt/main, or what will become Qt 4.4. You have already seen a random selection of screenshots and feature rundowns in previous blogs, but now it’s all in your hands to try and enjoy. It should appear in tonight’s snapshots.

I’d like to thank Jan-Arve, Bjørn Erik, Jo, Benjamin, Jasmin, Girish, Lars, and everyone else who has helped us with rowing this boat ashore. It was a beast, but we seem to have managed to tame it. Now, we’d all like for you to play around with this API, and let us know what you think.

Graphics View now provides a brand new layout and widget API. It’s similar to the way QWidget works, and should be familiar for most of you right away. The purpose of this API is mainly so you can write layout-aware items, but it also means you now have a richer base class for your items. Because QGraphicsWidget inherits from QObject, it allows declaring signals and slots and manages event delivery just like any widget in Qt. Like QWidget it also provides a palette, a font, layout directions and a style.

Graphics View doesn’t provide its own widgets like QLineEdit and QComboBox - instead, you can embed existing widgets (indeed, any custom widget that you have written yourself) into the scene by calling QGraphicsScene::addWidget(). If you also pass the Qt::Window flag, your widgets will even get window decorations similar to QMdiSubWindow. You can move, resize, rotate and scale your widgets, or combine widgets and items to generate fancy overlay or transition effects.

There are still a few remaining issues to solve. For one, Graphics View automatically embeds popups of embedded widgets. So if you embed a combobox, its popup will also appear as an embedded popup inside the scene. And QMenuBar’s menus also also embedded. We aim to make this feature work 100% for 4.4, but currently it doesn’t work properly (in particular, modality and mouse grabs are missing). Also, there’s the well-known Mac OS X styling problem. We still haven’t found a perfect solution for this, so for now, if you use Mac style for Graphics View, embedded widgets will look a bit chunky when transformed. And finally, because this is all brand new API, we expect some bugs to appear in this pre-alpha phase, and hope to iron them out based on your feedback. But hey - Widgets on Graphics View! How about it??? ;-)

PS: The members of the WOC project are all present and listening on qt4-preview-feedback@trolltech.com (also available through nntp.trolltech.com). Now is the time that you can help hone Widgets on Canvas to be just as great as we all want it to be. So enjoy! We’re eagerly awaiting your feedback.

Thomas Zander
KDE
Posted by Thomas Zander
 in KDE
 on Sunday, November 18, 2007 @ 15:22

Yesterday a big fog came in at around the evening hours. No, not the proverbial kind that comes after too much drinking (not doing much of that anyway with these Norwegian prices), real fog that feels clammy to the skin. I was down town, some blocks from sea and I couldn’t see the end of the street. Granted, that was a pretty long street, and there might have been some corners too. Point is; even back home, the weather is cold and sad. I don’t mind cold (too much), but sad weather makes me forget I actually have to get out of bed in the morning.

So, today is a day for staying inside. I put up a fire in the fireplace (awakened the boy in me!), and decided to write something for my blog. Which you are reading right now.

Watching the flames dance around the wood, scarring and ultimately consuming them, I’m doing some thinking and I’m actively ignoring the still foggy weather outside.

It has been almost 3 months since I left The Netherlands for Oslo/Norway. I found a new apartment (at an amazing location, even!), got a whole lot of new colleagues and friends, felt (well, still do) a little homesick because my father fell ill, and I can’t just go over to visit. Well, you know, the usual stuff for someone moving abroad.

It is fun seeing the simple differences between Norwegians and Dutch people. Last week I got asked in a restaurant what I wanted to drink. I ordered a cola and the lady immediately replied that they only had Pepsi cola. Did I still want a cola. Naturally I said no. In Holland I had the opposite happen to me various times. Actually I feel a more at home here in Oslo then I ever did in Enschede ;)

Yesterday I went to a market called “Bondensmarked”, or, in proper English; farmers-market. One thing I found since moving is that food is a lot more cultural then you’d at first expect. Bread is made very different in different countries. Germans buying bread in Holland will call it “fluffy”. I’ve been looking but can’t find various kinds of stuff you put on your sandwitch that I was used to having in Holland. Things like “vlokken” or “appelstroop”. But my worst experience so far is the Cheese situation.

Another Oslo-visiting guy already blogged about the situation once, and I can only agree. You can actually buy lots of foreign cheese in the average supermarket. But they tend to be English or French cheese. Which are more snacks then something you use in your cooking (though I’m sure some people do. Weird people are everywhere!). The guy that thought it was a good idea to call some kind of caramel candy “brune ost” (brown cheese) did a huge disfavor to the cheese movement.

Ok, I’m drifting away from my story here. I mean; the next guy creates a chocolate bar and should call it “brune ost-2″? O, right, the Bondensmarked…

Yesterday I went to a market called “Bondensmarked”. There I found a Dutch farmer that lives in Norway and uses the traditions from The Netherlands and he sells his cheese there. I talked a bit in Dutch and said how sad I was that my cookings tasted quite a lot more bland and simple without having access to good cheese.
I went ahead and got myself a piece and was about to shell over the 65 nkr for it. He then took it away and said he’d make me a special piece.
After that he cut a piece that was at least 4 times as large! Thanks for that!!

I guess he had experience with this already since I have been eating little pieces of this all morning, I hope it will last till the next market day…

My cheese situation has basically been solved totally, and I’m looking forward to making that lasagna I wanted to bake ;)

Simon
Qt
WebKit
Posted by Simon
 in Qt, WebKit
 on Friday, November 16, 2007 @ 11:27

It’s time for another update on “what’s happening” on the (Qt)WebKit side of things :)

  • We’ve been working on preparing the API for a first round of review. As a result of that we have finished the action API in QWebPage that I mentioned in my previous blog. QWebSettings has changed to a pointer based class: Every page returns a pointer to a QWebSettings object and there is static QWebSettings *QWebSettings::defaultSettings(). The individual attributes in the settings are inherited to QWebPage. This makes it easy to apply one global setting to all instances of QWebPage for example:
    QWebSettings *settings = QWebSettings::defaultSettings();
    settings->setAttribute(QWebSettings::JavascriptEnabled, false);
    
  • Lars has implemented a cool new class called QTextBoundaryFinder to find the boundaries for graphemes, words, lines (line breaks) and sentences in a QString. The text iterators in QtWebKit use this class now and provide correct navigation when live-editing is enabled on an HTML element.
  • We’re also working on integrating QtWebKit into Qt itself. Our goal is to include a snapshot of all the sources including the ones generated by build scripts into the Qt source tree. This will make it easier to build QtWebKit itself when it is shipped with Qt.
  • On top of that we are going to have a little QtWebKit hacking workshop next week here in our TT headquarters in Oslo. We plan to lock ourselves in an office and clean up some internals with the help of George and Adam.
  • BTW, Maciej has posted a nice summary about the features in WebKit 3 in the Surfin’ Safari WebKit Blog. QtWebKit is based on the same version and has all the features he describes.
englich
Qt
Aggregated
Patternist
Posted by englich
 in Qt, Aggregated, Patternist
 on Thursday, November 15, 2007 @ 10:52

People have asked for Qt’s XQuery & XPath support to not be locked to a particular tree backend such as QDom, but to be able to work on arbitrary backends.

Any decent implementation(such as XQilla or Saxon) provide that nowadays in someway or another, but I’d say Patternist’s approach is novice, with its own share of advantages. So let me introduce what Qt’s snapshot carries.

<ul>
    {
        for $file in $exampleDirectory//file[@suffix = "cpp"]
        order by xs:integer($file/@size)
        return <li>
                    {string($file/@fileName)}, size: {string($file/@size)}
                  </li>
    }
</ul>

and the query itself was set up with:

QXmlQuery query;FileTree fileTree(query.namePool());
query.setQuery(&file, QUrl::fromLocalFile(file.fileName()));
query.bindVariable("exampleDirectory", fileTree.nodeFor(QLibraryInfo::location(QLibraryInfo::ExamplesPath)));
if(!query.isValid())
     return InvalidQuery;
QFile out;
out.open(stdout, QIODevice::WriteOnly);
query.serialize(&out);

These two snippets are taken from the example found in examples/xmlpatterns/filetree/, which with about 250 lines of code, has virtualized the file system into an XML document.

In other words, with the tree backend FileTree that the example has, it’s possible to query the file system, without converting it to a textual XML document or anything like that.

And that’s what the query does: it finds all the .cpp files found on any level in Qt’s example directory, and generate a HTML list, ordered by their file size. Maybe generating a view for image files in a folder would have been a tad more useful.

The usual approach to this is an abstract interface/class for dealing with nodes, which brings disadvantages such as heap allocations and that one need to allocate such structures and hence the possibility to affect the implementation of what one is going to query.

But along time ago Patternist was rewritten to use Qt’s items & models pattern, which means any existing structure can be queried, without touching it. That’s what the FileTree class does, it subclasses QSimpleXmlNodeModel and handles out QXmlNodeModelIndex instances, which are light, stack allocate values.

This combined with that the engine tries to evaluate in a streamed and lazy manner to the degree that it thinks it can, means fairly efficient solutions should be doable.

So what does this mean? It means that if you would like to, you can relatively cheaply be able to use the XQuery language on top of your custom data structure, as long as it is somewhat hierarchical.

For instance, a backend could bridge the QObject tree, such that the XQuery language could be used to find Human Interface Guideline-violations within widgets; molecular patterns in a chemistry application can concisely be identified with a two or three liner XPath expression, and the documentation carries on with a couple of other examples. No need to convert QWidgets to nodes, or force a compact representation to sub-class an abstract interface.

A to me intriguing case would be a web robot that models the links between different pages as a graph, and finds invalid documents & broken links using the doc-available() function, or reported URIs that a website shouldn’t be linking to(such as a public site referencing intranet pages).

Our API freeze is approaching. If something is needed but missing, let me know.

Anders Larsen
Qt
Posted by Anders Larsen
 in Qt
 on Tuesday, November 13, 2007 @ 10:59

Some databases allow stored procedures and SQL batches to return multiple result sets. As some of you may have noticed Qt only allows you to access a single result set even when your query returns multiple, but as of Qt 4.4 this limitation will be history.

The cause of this joy is the newborn QSqlQuery::nextResult() which behaves very similar to QSqlQuery::next() with the exception that it navigates to the next result set instead of the next row. When a new result set is available it returns true and you can use next() as usual to iterate over its rows. Note that a result set can be empty and that a count of affected rows instead of a result set can be returned for non-SELECT statements.

A note of caution: not all databases are equal. For example some databases may execute all the statements in a stored procedure or SQL batch at once while others may delay the execution of each individual statement until the result set of the statement is actually accessed. Also, some databases may restrict which statements are allowed to be used in a stored procedure or SQL batch. If you run into problems you should first check what QSqlQuery::lastError() returns and then consult the documentation of your database.

As usual you should use QSqlDriver::hasFeature() to check whether the driver you’re using supports this feature or not. Currently nextResult() is implemented in the MySQL, ODBC and DB2 drivers.

If you’re too excited to wait for Qt 4.4 to play with this feature you can check out the snapshot for some adventurous fun.