View Full Version : QPainter and C function
shenakan
2nd November 2009, 14:38
I have a C function from an C program that I call from a widget.
This works! I use extern C to include the .h and call my function.
The problem is this function contain some calls to draw lines. I would like to draw lines with QPainter.
So I call my C function from my widget and how is possible to call drawLine from QPainter from my C function.
caduel
2nd November 2009, 17:18
you can't really.
(Unless you provide a C interface that calls QPainter for you and call that (new) interface from your C code... but if you have to modify the C code, why not turn it into C++ right away?)
shenakan
3rd November 2009, 08:55
The code is very big with lot of global variables so it is difficult to rewrite it in c++.But I can modifie the c code to call a draw line function but I dont know how to do that...
wysota
3rd November 2009, 09:15
The only way is to provide some global environment on which the C functions can operate but that's a very ugly solution.
QPainter *globalPainter;
void drawLine(int x1, int y1, int x2, int y2){
globalPainter->drawLine(x1, y1, x2, y2);
}
Of course the painter has to be properly initialized and it can't operate on QWidget.
shenakan
6th November 2009, 09:25
I find a solution.
I stock a global list of points computed from my C function call from QPainter. And I return than to qpainter to display them.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.