Support #2066
closedUsage of QPainter in WQApplication
Description
Hello! I want to know is it possible to draw with QPainter on QImage (for example) in WQApplication. Other questiong is what restriction WPainter has compared to QPainter?
Thank you.
Files
Updated by Koen Deforche over 11 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
Hey,
We've never done that, but I wouldn't see why that doesn't work (assuming that Qt allows the use of QPainter and QImage in a 'console' application?).
WPainter provides pretty much the same API as QPainter; it's main differences are in API to load images, and Wt also has not as much support of computing (mathematically) properties of painted painter paths (e.g. intersections etc...).
Regards,
koen
Updated by Vitaly Volochay over 11 years ago
Thanks for you answer!
I tried code below and it works widget with picture shows up (its in WQApplication::create()):
QString imageName = "qimage.png";
QPainter painter;
painter.setPen(QPen(Qt::color1));
painter.drawRect(QRect(0,0,50,50));
painter.end();
image.save(imageName);
Wt::WFileResource *imageFile = new Wt::WFileResource("image/png", imageName.toStdString());
Wt::WImage *wImage = new Wt::WImage(imageFile, "PNG version");
mainLayout->addWidget(wImage, 1);
but there is a problem: when I navigate in menu (WNavigationBar with WMenu), warning popup windows appears: "Wt internal error: SyntaxError: Unexpected token ILLEGAL, code: undefined, description: undefined". I think it somehow linked with changes in internal path. I also figured out that all this happens because of one string:
image.save(imageName);
If I remove this one - no problem solved, but i don't see another way to pass QImage -> WImage without saving it to file.
Can you tell me how to fix it please?
Updated by Koen Deforche over 11 years ago
Hey,
I cannot link this error to setting a filename to the image. Would be it easy for you to isolate this problem in a small test case for us to investigate?
Regards,
koen
Updated by Vitaly Volochay over 11 years ago
It's not because of setting file name of image but because of saving it to file on disk. I will write minimum application and attach it here.
Updated by Vitaly Volochay over 11 years ago
Seems like I localized a problem. There is no problem with internal path, there is a problem with WPaintedWidget. After I call QImage::save() and then create inheritor of WPaintedWidget there popup warning starting to appear.
Seems like I've got similar problem as this: http://redmine.webtoolkit.eu/boards/2/topics/6445
If you want I will attach min application.
Updated by Wim Dumon over 11 years ago
Maybe see the answer here: http://redmine.webtoolkit.eu/boards/2/topics/6462
So can you verify that Qt didn't sneakily modify your C locale? Wt requires that the selected C locale formats its numbers like the default C locale, which isn't the case on some locales.
Wim.
Updated by Vitaly Volochay over 11 years ago
I don't even create QCoreApplication and setlocale(LC_NUMERIC,"C") doesn't help me.
I create an example, it shows that after I save QImage I can't create WPaintedWidget inheritors. Source file is in attachment.
Updated by Koen Deforche over 11 years ago
Hey,
It works for me, even when commenting out setLocale() and adding a QCoreApplication to main().
This is with Wt's latest git (although I suspect that doesn't matter) and Qt 4.8.1 on Ubuntu.
I'm curious what's affecting your (and the other reported) WPaintedWidget though. Except for locale I cannot imagine how Qt can interfere with it. Could you capture the requests in Chrome and send me the last one when you get the failure?
Regards,
koen
Updated by Vitaly Volochay over 11 years ago
Koen Deforche wrote:
Hey,
It works for me, even when commenting out setLocale() and adding a QCoreApplication to main().
This is with Wt's latest git (although I suspect that doesn't matter) and Qt 4.8.1 on Ubuntu.I'm curious what's affecting your (and the other reported) WPaintedWidget though. Except for locale I cannot imagine how Qt can interfere with it. Could you capture the requests in Chrome and send me the last one when you get the failure?
Regards,
koen
I tried it and mozilla and sometimes it works fine, but sometimes I relauch wt server and get this error:
"Wt internal error: SyntaxError: identifier starts immediately after numeric literal, code: undefined, description: undefined".
In chrome it also sometimes works, sometimes - not, behaviour seems so random but in my other real application I always have errors.
When i have errors requests are the same as if no problems and lookes like:
"POST http://ip:port/?wtd=uywE550jtPR3zY8S [HTTP/1.1 200 OK 1мс]"
May be there are some other way to pass QImage to WImage without save it to file and then load (may be load it from byte array - char* or something)?
Updated by Koen Deforche over 11 years ago
Hey,
You should be able to see the response of the failed request in the developer tools.
What version of boost are you using?
Regards,
koen
Updated by Vitaly Volochay over 11 years ago
I am not familiar with web programming, sorry. Response looks like:
\"Wt.p.response(--1518218007);{var j4=Wt3_3_0.$('oqvy5h6');
var j5=document.createElement('div');j4.appendChild(j5);
j5.setAttribute('id', 'oqvy5gx');
j5.style.width='50.0px';
j5.style.height='50.0px';
j5.style.maxWidth='50.0px';
j5.style.maxHeight='50.0px';
j5.style.visibility='hidden';
Wt3_3_0.setHtml(j5,'
');
if(Wt3_3_0.getElement('coqvy5gx').getContext){{var ctx=Wt3_3_0.getElement('coqvy5gx').getContext('2d');ctx.clearRect(0,0,50,50);ctx.save();ctx.save();ctx.lineWidth=1;ctx.lineCap='square';ctx.fillStyle='rgb(0,255,0)';ctx.font='10.0pt sans-serif ';ctx.beginPath();ctx.moveTo(0,0000000e+00,0,0000000e+00);ctx.lineTo(5,0000000e+01,0,0000000e+00);ctx.lineTo(5,0000000e+01,5,0000000e+01);ctx.lineTo(0,0000000e+00,5,0000000e+01);ctx.lineTo(0,0000000e+00,0,0000000e+00);ctx.moveTo(0,0000000e+00,0,0000000e+00);ctx.fill();
ctx.restore();ctx.restore();}}
Wt3_3_0.$('oqvy5gx').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gx').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gx').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gx').wtResize(Wt3_3_0.$('oqvy5gx'),50,50,false);;
Wt.layouts2.updateConfig('oqvy5h6',{ rows:0,0,0],[0,0,0],[0,0,0, cols:--1,0,12, items: [{align:16,id:'oqvy5h1'},{align:16,id:'oqvy5gz'},{align:16,id:'oqvy5gx'}]});
}{var j6=Wt3_3_0.$('oqvy5h6');
var j7=document.createElement('div');j6.appendChild(j7);
j7.setAttribute('id', 'oqvy5gu');
j7.style.width='50.0px';
j7.style.height='50.0px';
j7.style.maxWidth='50.0px';
j7.style.maxHeight='50.0px';
j7.style.visibility='hidden';
Wt3_3_0.setHtml(j7,'
');
if(Wt3_3_0.getElement('coqvy5gu').getContext){{var ctx=Wt3_3_0.getElement('coqvy5gu').getContext('2d');ctx.clearRect(0,0,50,50);ctx.save();ctx.save();ctx.lineWidth=1;ctx.lineCap='square';ctx.fillStyle='rgb(0,255,0)';ctx.font='10.0pt sans-serif ';ctx.beginPath();ctx.moveTo(0,0000000e+00,0,0000000e+00);ctx.lineTo(5,0000000e+01,0,0000000e+00);ctx.lineTo(5,0000000e+01,5,0000000e+01);ctx.lineTo(0,0000000e+00,5,0000000e+01);ctx.lineTo(0,0000000e+00,0,0000000e+00);ctx.moveTo(0,0000000e+00,0,0000000e+00);ctx.fill();
ctx.restore();ctx.restore();}}
Wt3_3_0.$('oqvy5gu').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gu').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gu').wtResize=function(self, w, h) {var u = $(self).find('canvas, img');if (w >= 0) u.width(w);if (h >= 0) u.height(h);};
Wt3_3_0.$('oqvy5gu').wtResize(Wt3_3_0.$('oqvy5gu'),50,50,false);;
Wt.layouts2.updateConfig('oqvy5h6',{ rows:0,0,0],[0,0,0],[0,0,0],[0,0,0, cols:--1,0,12, items: [{align:16,id:'oqvy5h1'},{align:16,id:'oqvy5gz'},{align:16,id:'oqvy5gx'},{align:16,id:'oqvy5gu'}]});
}\"
I am using boost: 1.41.0
Updated by Koen Deforche over 11 years ago
- Assignee changed from Koen Deforche to Wim Dumon
Hey,
That's definitely a locale problem. The numbers are being serialized using ',' as decimal point instead of '.'.
Wim, any idea how this can be solved?
Regards,
koen
Updated by Wim Dumon over 11 years ago
setlocale(LC_NUMERIC,"C");
in the right place should be the answer.
Maybe the call to QPainter::save() changes the locale (that's what I call an unexpected side effect)? So did you try to put this call right after image.save()?
BR,
Wim.
Updated by Vitaly Volochay over 11 years ago
Seems like you're right and QPainter::save change locale. When I call setlocale after image.save() everything is OK. Thanks for your help!