LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-05-2005, 12:24 PM   #1
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Rep: Reputation: 22
Talk to an object in a diferent class


Hi to all.
I want to talk to an object in an other class.
I want to stream in data from a file into a TextEdit-Object on "open File".
Like this:


QFile f1( file1 );
if ( f1.open( IO_ReadWrite) )
{
QTextStream stream1( &f1 );
TextEdit_1->setText( stream1.read() );
}

So the object is in an other class.
KDE app, QT-designer based, so TextEdit_1 is in the designer based
class and the open_file function in the kde MainWindow class.

Now my question: How can I make this work?
 
Old 03-05-2005, 02:15 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Not sure if that's exactly what you want, but I'd make a connection (signal - slot) between menu entry and function that'd fill the widget.
 
Old 03-06-2005, 01:19 PM   #3
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
O.K., I handled a little with signals and the result is:

error: cannot call member function `void designer_based::readin(QString)' without object
readin is just a function in the designer-class-body.

I think standard signals are not a good idea, so I have to re implement QTextEdit there - am I right?
 
Old 03-06-2005, 03:06 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Yes, bu adding it a new slot and implementing it.
 
Old 03-13-2005, 10:50 AM   #5
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
O.K. C++ signals seems to be not allowed in Qt-designer (moc).
So I studied all about events and what is the best for my problem and did read the book "C++ GUI Programming with Qt 3".
Now I programmed with:
QCustomEvent ( int type ) - I use "1001" for my event(open File)
customEvent
All compiled pretty so far, but when I "make" that event(open File) in my app it crashes with exit code 253.
What happened? Is that a protection fault?
What details have I to write here, that you can help me?

Last edited by bastl; 03-13-2005 at 10:57 AM.
 
Old 03-14-2005, 06:03 AM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Run your program under gdb (compile in debig mode with -g option). Cause it to crash, gdb should tell you which function it was, then you can use 'bt' gdb command to see the sequence of function calls that led to the problem.
 
Old 03-14-2005, 04:44 PM   #7
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
O.K, I get this:
Program received signal SIGSEGV, Segmentation fault.

Yes, the signal is right, but segmentation fault?

I think it's the same case like with c++ signals. Functions in Qt-classes
can only be called over signals of a Q_OBJECT - in short, only something visible can call a Qt-member-function?
And my only disadvantage is that it isn't allowed to do source coding in kdesigner.

So I think I have to write and add a custom widget including QTextEdit that I can put in my layout with kdesigner. And that custom widget has to have a signal that can not be emit by the user or the system.
So if I emit that signal in the c++ body it should work?
Now I'll study a little more about custom widgets in QT-Designer.
Now I'm at point 3 again.

Maybe you have a better idea.
I have only to call myTextEdit->setText(..) of mydesigner.ui class of mycentralwidget.h class from my.cpp::fileOpen(..) slot of KMainWindow class.

Last edited by bastl; 03-15-2005 at 12:07 AM.
 
Old 03-15-2005, 04:00 PM   #8
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I'd say is rather an uninitialized pointer or something similar, but it's hard to say without seeing the whole code.
 
Old 03-16-2005, 11:19 AM   #9
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
I use a project generated by Kdevelope 3.1.2 named test -
New Project / c++ / KDE / Application framework.
In testview.cpp and .h I made changes to a designer based application
like this:
testView::testView(QWidget* parent, const char* name, WFlags fl )
: M3Dansicht(parent,name,fl )

M3Dansicht is in 3Dansicht.ui and is now my central widget.

I think KMainWindow has an eventloop and M3Dansicht too.
The menu and the toolbar are KMainWindow events, and that what I want to do [ ncbefehlseditor->setText(str1.read()); ] is in the M3Dansicht event loop.
And whatever I do to connect to these events (functions) I get an error or crash.
 
Old 03-17-2005, 01:36 PM   #10
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Original Poster
Rep: Reputation: 22
O.K., I get it.
I didn't recognize that in test.cpp the central widget was set - so I have
access over "this->centralWidget()" to my slots of my .ui file.
Nevertheless many thanks to you, Mara.
 
  


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
URGENT: ldap_add(): Add: Object class violation error 65 sierraaltae Linux - Security 1 08-05-2005 10:41 AM
Pass object variable to anothor class in JAVA hus Programming 2 05-11-2005 04:04 AM
C++ class-object? shivaligupta Programming 2 01-06-2005 02:25 AM
talk talk daemon configuration ananthkrk Red Hat 1 10-16-2004 11:45 AM
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 01:42 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