Results 1 to 5 of 5

Thread: QPainter and C function

  1. #1
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QPainter and C function

    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.

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter and C function

    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?)

  3. #3
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QPainter and C function

    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...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter and C function

    The only way is to provide some global environment on which the C functions can operate but that's a very ugly solution.

    Qt Code:
    1. QPainter *globalPainter;
    2.  
    3. void drawLine(int x1, int y1, int x2, int y2){
    4. globalPainter->drawLine(x1, y1, x2, y2);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Of course the painter has to be properly initialized and it can't operate on QWidget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2009
    Posts
    30
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QPainter and C function

    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.

Similar Threads

  1. Must QPainter be in paintEvent ??
    By jiapei100 in forum Qt Programming
    Replies: 6
    Last Post: 5th September 2009, 00:09
  2. Qpainter function on a QFrame problem
    By impeteperry in forum Newbie
    Replies: 45
    Last Post: 14th October 2008, 12:43
  3. how to create a new function
    By tommy in forum Qt Programming
    Replies: 3
    Last Post: 10th November 2007, 17:08
  4. Replies: 7
    Last Post: 20th March 2006, 20:03
  5. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.