LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-20-2005, 07:39 AM   #1
vratojr
LQ Newbie
 
Registered: Nov 2005
Location: La Spezia,Italy
Distribution: Mandrivia 10.2
Posts: 7

Rep: Reputation: 0
passing a QPainter object to widgets


Hello,
I'm writing a program that acts this way:
- I have a principal QWidget over which I create a QPainter,
- I draw on the widget,
- I pass the Painter to other widgets so I can use those widgets to draw on the principal one,
- Finally,in the principal widget,I call end() on the painter.

The program works properly but ends with a segmentation fault. I runned gdb and it sais that the problem was that it doesn't found qlist.h (quite strange I think).

However the output has no apparent problem:I can display the result of my painting on video and I can eventually draw it on a file. The problem arises when I try to convert the .ps image created with my program to a .pdf,in fact I obtain this error using dvipdf ( in fact I use the .ps file I create as an image in a latex text):

/usr/bin/dvipdf: line 40: 20896 Broken pipe exec dvips -q -f "$infile"
20897 Segmentation fault | gs $OPTIONS -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$outfile" $OPTIONS -c .setpdfwrite -

I'm sure it's not a problem of the latex file or of my dvipdf because if I do the same things but without passing the QPainter to other widgets,I have no problem.

What can I do?

thanks!
 
Old 12-20-2005, 02:54 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
What do you pass exactly to the other widgets? Is it possible that the Painter gets destroyed before your widgets try to use it?
 
Old 12-21-2005, 02:46 AM   #3
vratojr
LQ Newbie
 
Registered: Nov 2005
Location: La Spezia,Italy
Distribution: Mandrivia 10.2
Posts: 7

Original Poster
Rep: Reputation: 0
This is the way the program behaves essentially:

class SecondWidget{//The class to whom I pass the painter
public:
SecondWidget(...,QPainter &painter,...) {p=painter;}
private:
void draw();
QPainter p;
};

SecondWidget::draw(){
p.drawSomething.......
}


class MainWidget{//The main class
...
public slot:
void paintEvent(QPaintEvent *event);
private:
SecondWidget *secondWidget;
..
};

MainWidget:aintEvent(..){
QPainter paint(this);
paint.draw...
//i draw somthing with the painter
//then I pass it to the other widget
secondWidget = new SecondWidget(paint);
secondWidget->draw();
paint.end();
}


That's all. No,I think it's impossible that the painter gets destroyed before the widget tryies to use it because the compiler whould signal it. Moreover,I don't call any .end() on the painter before the end of the program and the output I get is correct (i.e. the widgets draw what they are supposed to draw).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
widgets bullettobinary Linux - Software 1 10-22-2005 01:50 AM
kdevdesigner Help! "QPainter::begin: Cannot paint null pixmap" LBS Linux - Software 4 05-18-2005 05:11 PM
widgets purevil Linux - Newbie 1 05-15-2005 02:31 PM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
Event driven object-to-object: C++ template class mecanism ( NOT STL or STDC++) bretzeltux Programming 2 12-23-2003 02:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration