Project

General

Profile

Wt and Qt compatibility issue

Added by Alan Finley over 7 years ago

I'm trying to create an application based on both Wt (3.2.3) and Qt (4.6.2) frameworks.

First I create a pure Wt application - a painter widget taken from the official examples - and it works.

Then, I initialize a QCoreApplication object in the main function and my painter stops drawing images.

I have no any Qt stuff in my app, just a single QCoreApplication object.

What am I doing wrong?


Replies (6)

RE: Wt and Qt compatibility issue - Added by Koen Deforche over 7 years ago

Hey Alan,

It sounds like Qt is interfering with Wt in new (unexpected) ways. Do you have this as a small test case for us to look into it ?

Regards,

koen

RE: Wt and Qt compatibility issue - Added by Alan Finley over 7 years ago

Here's the code:

class ImagePainter : public Wt::WPaintedWidget
{
public:
    ImagePainter(Wt::WContainerWidget *parent = 0);

protected:
    void paintEvent(Wt::WPaintDevice *paintDevice);
};

ImagePainter::ImagePainter(Wt::WContainerWidget *parent)
    : WPaintedWidget(parent)
{
    resize(400, 400);

    Wt::WCssDecorationStyle style = decorationStyle();
    style.setBorder(Wt::WBorder(Wt::WBorder::Solid, 4, Wt::red));
    setDecorationStyle(style);
}

void
ImagePainter::paintEvent(WPaintDevice *paintDevice)
{
    Wt::WPainter painter(paintDevice);
    Wt::WPainter::Image image("icons/sp.jpg", 199, 253);
    painter.drawImage(0.0, 0.0, image);
}

Wt::WApplication*
createApplication(const Wt::WEnvironment& env)
{
    Wt::WApplication *app = new Wt::WApplication(env);

    ImagePainter *p = new ImagePainter(app->root());

    return app;
}

int
main(int argc, char **argv)
{
    // QCoreApplication app(argc, argv); <-- uncomment this and the painter won't work properly
    return WRun(argc, argv, &createApplication);
}

RE: Wt and Qt compatibility issue - Added by Wim Dumon over 7 years ago

Hi Alan,

For me this works, also when the QCoreApplication line is uncommented.

I added the following to the top of the example to make it compile:

#define QT_NO_KEYWORDS
#define WT_NO_SLOT_MACROS
#include <QCoreApplication>
#include <Wt/WPaintedWidget>
#include <Wt/WPaintDevice>
#include <Wt/WPainter>
#include <Wt/WContainerWidget>
#include <Wt/WApplication>
#include <Wt/WCssDecorationStyle>

(and then I had to fix some trivial namespace)

From your previous post (http://redmine.emweb.be/boards/2/topics/6380) it looks like your float rendering goes bezerk. A normal paint block would look like:

    if (Wt3_3_0.getElement('coz5wg3q').getContext) {
        new Wt._p_.ImagePreloader(['/icons/a.jpg'], function(images) {
            var ctx = Wt3_3_0.getElement('coz5wg3q').getContext('2d');
            ctx.clearRect(0, 0, 400, 400);
            ctx.save();
            ctx.save();
            ctx.lineWidth = 1;
            ctx.lineCap = 'square';
            ctx.font = '10.0pt sans-serif ';
            ctx.drawImage(images[0], 0, 0, 200.0, 400.0, 0, 0, 200.0, 400.0);
            ctx.restore();
            ctx.restore();
        });
    }

Wt has several float rendering strategies depending on your boost version etc, can you tell me what path is followed for you, and maybe if you can step through that part of the code, find out what's going wrong? You find the code in src/web/WebUtils.c, function round_js_str or round_str, depending on your Wt version.

BR,

Wim.

BR,

Wim.

RE: Wt and Qt compatibility issue - Added by Alan Finley over 7 years ago

I've added those definitions, but it didn't help.

I've followed your advice and checked the float conversion.

When my painter works, I've got this:

ctx.drawImage(images[0], 0.000000, 0.000000, 199.000, 253.000, 0.000000, 0.000000, 199.000, 253.000);

When I uncomment QCoreApplication line, I've got this:

ctx.drawImage(images[0], 0, 000000, 0, 000000, 199.000, 253.000, 0, 000000, 0, 000000, 199.000, 253.000);

In the second case It's clear that zero values are incorrect.

In the src/web/WebUtils.c I have the round_str function, but I don't understand how its behaviour can be affected by creating a QCoreApplication object.

RE: Wt and Qt compatibility issue - Added by Wim Dumon over 7 years ago

The QCoreApplication constructor changes the C locale according to the documentation, and for some floats we render with snprintf() which is influence by the locale.

Can you put this right after the QCoreApplication constructor:

setlocale(LC_NUMERIC,"C")

Wim.

RE: Wt and Qt compatibility issue - Added by Alan Finley over 7 years ago

Setting the C locale worked a treat.

Thank you, Wim!

    (1-6/6)