Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, February 2007
Calling a function from a dialog window


Message 1 in thread

Thank you again for reading this.

I now have another problem, which may not be strictly related to the Qt
mailing list. However, since the answer is, no doubt obvious, someone may be
willing to put me on the right track.

I have two buttons that call two functions in the main section of the
program. The first one generates a matrix of characters and the second one
is supposed to print that matrix. The problem is that it doesn't print what
I want and the reason for that is, if I understand this correctly, I am
using two different instances of type "word" within the slot functions.

I tried a global instance of "word" but that causes the following error:

QPaintDevice: Must construct a QApplication before a QPaintDevice

I also thought about passing "word" to the Print function like this,
Print(wordsearch word), but that caused another problem that made me think
that I was on the wrong track.

How do I get around this problem? By the way, the print function does work
correctly if it's called from the main section of the program and not from
the dialog window.

These are the two slot functions that are called when the buttons are
clicked.

void wordsearchWidget::GeneratePuzzle()
{
    wordsearch word;
    word.GeneratePuzzle();
}


void wordsearchWidget::Print()
{
    wordsearch word;
    word.Print();
}

Regards,
Phil.

--
 [ signature omitted ] 

Message 2 in thread

> if I understand this correctly, I am
> using two different instances of type "word" within the slot functions.

Exactly.
  
> I also thought about passing "word" to the Print function like this,
> Print(wordsearch word), but that caused another problem that made me think
> that I was on the wrong track.

What was this problem?


Anyway,
try: Print(wordsearch &word) 
or if possible (hopefully):
Print(const wordsearch &word) 

Guido


--
 [ signature omitted ] 

Message 3 in thread

Btw, regardless how you try to pass your wordsearch from GeneratePuzzle 
to Print, it won't work. You create a local copy of wordsearch in
GeneralPuzzle, which will cease to exist as soon as you leave your
GeneratePuzzle slot. 

*sigh* That I did not see it before. 

Guido


> QPaintDevice: Must construct a QApplication before a QPaintDevice

> void wordsearchWidget::GeneratePuzzle()
> {
>    wordsearch word;
>    word.GeneratePuzzle();
> }
> 
> 
> void wordsearchWidget::Print()
> {
>    wordsearch word;
>    word.Print();
> }

--
 [ signature omitted ] 

Message 4 in thread

Phil schrieb:
> I tried a global instance of "word" but that causes the following error:
> 
> QPaintDevice: Must construct a QApplication before a QPaintDevice

So why don't you?

Martin

-- 
 [ signature omitted ] 

Message 5 in thread

On Thu, 2007-02-08 at 03:41 -0500, Martin Gebert wrote:

> Phil schrieb:
> > I tried a global instance of "word" but that causes the following
> error:
> >
> > QPaintDevice: Must construct a QApplication before a QPaintDevice
> 
> So why don't you?
> 
> Martin
> 
> --
> To mail me in private, please remove the -NOSPAM- part from the adress
> above.
> 
> Ultimate Truths in software development # 6:
> If your program is idiot-proof, they'll find a better idiot.
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

For this response, I am assuming that "word" is an instance of a class
that contains a QPaintDevice. When I need a global instance of a class
that contains Qt elements, I create a global pointer to that class, then
instantiate an instance after creating my QApplication in main. i.e.

    wordClass *word;

int main(argc, char **argv)
{
    QApplication myApp(argc, argv);
    word = new wordClass;

--------------------------------------+--------------------------
  John W. McClurkin, PhD.             | jwm@xxxxxxxxxxxxxxx
  Information Technology Specialist   | VOX:  301-496-9216
  Laboratory of Sensorimotor Research | FAX:  301-409-0511
  National Eye Institute, NIH         |
--------------------------------------+--------------------------



Message 6 in thread

----- Original Message ----- 
From: "John McClurkin - LMO" <jwm@xxxxxxxxxxx>
To: "Martin Gebert" <Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Cc: <qt-interest@xxxxxxxxxxxxx>
Sent: Thursday, February 08, 2007 10:20 PM
Subject: Re: Calling a function from a dialog window


> For this response, I am assuming that "word" is an instance of a class
> that contains a QPaintDevice. When I need a global instance of a class
> that contains Qt elements, I create a global pointer to that class, then
> instantiate an instance after creating my QApplication in main. i.e.
>
>    wordClass *word;
>
> int main(argc, char **argv)
> {
>    QApplication myApp(argc, argv);
>    word = new wordClass;
>

Once again thank you everyone for the responses to my questions. However, it
seems that I was led astray by the "QPaintDevice: Must construct a
QApplication before a QpaintDevice" error message.

I thought my problem would be solved if I could create a global instance of
the class wordsearch and I was shown how to do just that. I had earlier used
a class member attribute, as I have done in the past, but this also caused
the main window not to display and this is where I think the real problem
is.

I really thought that I was onto the answer after reading John's response
but word is not visible inside the wordsearchWidge class (word not in scope
error)

The debugger stops when it reaches this statement "setCentralWidget( new
wordsearchWidget( this ) );" If I leave this statement out then a blank
window (and itâs not wordsearchWidgetBase) is displayed.

I really don't know how to proceed from here and so I will have to abandon
the project (it's not a matter of life and death) until I can find a
suitable example or stumble onto the answer.

Thanks again for the assistance provided.

Regards,
Phil.

--
 [ signature omitted ] 

Message 7 in thread

Hi,

Am Samstag, 10. Februar 2007 13:38:14 schrieb Phil:
> Once again thank you everyone for the responses to my questions. However,
> it seems that I was led astray by the "QPaintDevice: Must construct a
> QApplication before a QpaintDevice" error message.
>
> I thought my problem would be solved if I could create a global instance of
> the class wordsearch and I was shown how to do just that. I had earlier
> used a class member attribute, as I have done in the past, but this also
> caused the main window not to display and this is where I think the real
> problem is.

Did you try a class member pointer? That worked fine for me (I had a similar 
constellation some time ago, but without Qt).

> I really thought that I was onto the answer after reading John's response
> but word is not visible inside the wordsearchWidge class (word not in scope
> error)

did you try to access the global scope using ::word ?

Perhaps it is easier to help you if you could upload a little application 
demonstrating the problem.

I hope I could help you,
Ralf


--
 [ signature omitted ] 

Message 8 in thread

On 10.02.07 21:38:14, Phil wrote:
> I really don't know how to proceed from here and so I will have to abandon
> the project (it's not a matter of life and death) until I can find a
> suitable example or stumble onto the answer.

Uhm, there are plenty of examples coming with Qt, when you read and
understand those you will be able to solve your problem.

Andreas

-- 
 [ signature omitted ] 

Message 9 in thread

On Sat, 2007-02-10 at 07:38 -0500, Phil wrote:

> 
> ----- Original Message -----
> From: "John McClurkin - LMO" <jwm@xxxxxxxxxxx>
> To: "Martin Gebert" <Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Cc: <qt-interest@xxxxxxxxxxxxx>
> Sent: Thursday, February 08, 2007 10:20 PM
> Subject: Re: Calling a function from a dialog window
> 
> 
> > For this response, I am assuming that "word" is an instance of a
> class
> > that contains a QPaintDevice. When I need a global instance of a
> class
> > that contains Qt elements, I create a global pointer to that class,
> then
> > instantiate an instance after creating my QApplication in main. i.e.
> >
> >    wordClass *word;
> >
> > int main(argc, char **argv)
> > {
> >    QApplication myApp(argc, argv);
> >    word = new wordClass;
> >
> 
> Once again thank you everyone for the responses to my questions.
> However, it
> seems that I was led astray by the "QPaintDevice: Must construct a
> QApplication before a QpaintDevice" error message.
> 
> I thought my problem would be solved if I could create a global
> instance of
> the class wordsearch and I was shown how to do just that. I had
> earlier used
> a class member attribute, as I have done in the past, but this also
> caused
> the main window not to display and this is where I think the real
> problem
> is.
> 
> I really thought that I was onto the answer after reading John's
> response
> but word is not visible inside the wordsearchWidge class (word not in
> scope
> error)

If word is global to the application, shouldn't it be visible to all
parts of the application?

> 
> The debugger stops when it reaches this statement "setCentralWidget
> ( new
> wordsearchWidget( this ) );" If I leave this statement out then a
> blank
> window (and itâs not wordsearchWidgetBase) is displayed.
> 
> I really don't know how to proceed from here and so I will have to
> abandon
> the project (it's not a matter of life and death) until I can find a
> suitable example or stumble onto the answer.
> 
> Thanks again for the assistance provided.
> 
> Regards,
> Phil.
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 

--------------------------------------+--------------------------
  John W. McClurkin, PhD.             | jwm@xxxxxxxxxxxxxxx
  Information Technology Specialist   | VOX:  301-496-9216
  Laboratory of Sensorimotor Research | FAX:  301-409-0511
  National Eye Institute, NIH         |
--------------------------------------+--------------------------