LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 12-12-2008, 11:07 AM   #1
Luis Navarro
LQ Newbie
 
Registered: Dec 2008
Location: Brazil, Parana State, portuguese language.
Distribution: Fedora V8
Posts: 4

Rep: Reputation: 0
C++ Qt visibility


I'm new in linux (fedora v8) and in Qt & QtDesigner(4.4.1 - GNU-GLP).
I'm trying to re-write a proprietary (mine) applicaton who was functioning ok in Windows with BorlandBuilderC++ to the new environment Linux+Qt in order to become an GNU-GLP-application. I'm not an expert in OOP but I know C and C++(basicly) enough to arrive where I am.

My problem, I beelive, is about visibility(?) .
I have several modules among them I quote the following 5 routines presented to the compiler in that order:
------------------------------------------
wp120.h
#include "ui_QTwp120.h" // includes QtDesigner files
extern class Janela000 *win000; //
class Janela120 : public QWidget, private Ui::Form120
{ Q_OBJECT //
public: Janela120(QWidget *win000); //
public slots: //
... //
void load120(void); // the "problematic" routine header
... }; //
------------------------------------------
wp120.cpp
#include "wp120.h" // includes the 120 header file
Janela120::Janela120(QWidget *) // Constructor
{ setupUi(this); ........ // constructor statements....
}; // end-of-function
void Janela120::load120(void) // the "problem" routine statements.
{ ... // Procedures that must be executed
show(); // ...and show the window
}; // end-of-function
------------------------------------------
wp000.h
#include "ui_QTwp000.h" // includes QtDesigner files
class Janela000 : public QMainWindow, private Ui::Form000
{ Q_OBJECT //
public: Janela000(QMainWindow *parent=0);
public slots: //
... //
void load000(void); // loading routine header
void click_in_b1(void); // header to the "problematic" routine
... }; //
------------------------------------------
wp000.cpp
#include "wp000.h" // includes 000 header file
Janela000::Janela000(QMainWindow *) // Constructor
{ setupUi(this); ........}; // constructor statements....
void Janela000::load000(void) // loading routine

{ ... //

show(); // shows 000 window
}; // end-of-function
void Janela000::click_in_b1(void) // routine where I need to call load120

{ ... // ...activated with a click in pushButton_1

hide(); // hide 000 window. It will be showed in another time.
load120(); // call to load the 120 window (problem is here?)
}; // end-of-function
------------------------------------------
programa.cpp // main program
#include "wp120.cpp" // includes 120 window (widget)
#include "wp000.cpp" // includes 000 Main Window
int main (argc,argv[]) //
{ ........ //
Janela000 *win000 = new Janela000; // creates windows instances
Janela120 *win120 = new Janela120(win000);
........ //
win000->load000(); // calls loading Main Window
........ //
}; //
------------------------------------------
The program compiles and functions only if I suppress the line whose comentary is "(problem is here?)" but obviously the 120 window lies dead.

If the program is like above, the compiler (g++) quotes the error:
in function Janela000::click_in_b1()
undefined reference to 'load120()'

I've tried to put in wp000.cpp module an statement like (several different tries):
extern void load120(void);
or
extern void Janela120::load120(void);
or
extern void Janela120::win120->load120(void);
or
extern void win120->load120(void);

but the compiler insist in not seen the definition of load120()

I've tried too, to put those extern statements in the wp000.h file and none result.

I've tried also to change the routine's call (the statement whose comentary is: "(problem is here?)" with

win120->load120();
or with
Janela120::load120();
or with
Janela120::win120->load120();

but none again.

I've too tried to change the order in which the modules are presented to the g++ ...

but none again.

Can someone give me a help?
I'll be gratefull.

Luis
 
Old 12-12-2008, 11:35 AM   #2
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Mepis, Centos
Posts: 4,012

Rep: Reputation: 731Reputation: 731Reputation: 731Reputation: 731Reputation: 731Reputation: 731Reputation: 731
If I understand you correctly:

load120 is a public member function of Janela120, so it can only be called using an object of type Janela120.
I don't see the source code for load120, so I can only assume it is declared correctly (meaning it actually does need a Janela120 object in order to do its job. Otherwise, it would be better to make it a static member function.)

win120 is a local variable in the function main() so it can't be used anywhere else. Did you maybe intend win120 to be a global variable?

Quote:
Originally Posted by Luis Navarro View Post
Code:
void Janela000::click_in_b1(void)      // routine where I need to call load120
So you want to call load120 from a member function of another class and that other class is not derived from the class in which load120 is declared.

Quote:
Code:
  load120();                           // call to load the 120 window (problem is here?)
Nothing there provides the needed object.

Quote:
I've tried to put in wp000.cpp module an statement like (several different tries):
extern void load120(void);
That declares a different load120, which you never defined, so the compiler will let you call it, but the linker won't find it.

Quote:
extern void Janela120::load120(void);
or
extern void Janela120::win120->load120(void);
or
extern void win120->load120(void);
All garbage.

Quote:
win120->load120();
Would be OK if win120 were global. But win120 is a local variable in main().

Quote:
or with
Janela120::load120();
Would be OK if load120 were a static function in that class, but a non static member function requires an object.

Quote:
or with
Janela120::win120->load120();
Would be OK if win120 were declared, defined and initialized as a static pointer in that class (which is a common way of managing this sort of situation) but I can't tell if that is what you want and anyway it isn't what you did.

BTW, I haven't programmed anything in QT. I expect QT has some usual form for dealing with this issue (accessing methods inside a widget from somewhere outside that widget). What I told you is how one might deal with this issue in ordinary C++. That might or might not be a good answer for QT.

Last edited by johnsfine; 12-12-2008 at 11:44 AM.
 
Old 12-12-2008, 11:36 AM   #3
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 61
You don't include *.cpp files with #include directive. You shouldn't ever attempt to do it, even without Qt.

Qt uses custom preprocessor (I suppose you are building project using qmake (the only correct way for Qt), right?) and including file into project this way will probably "break" it. Including *.cpp with include might work only when there are no objects in file that are derived from Qt4 classes.

Last edited by ErV; 12-12-2008 at 11:37 AM.
 
Old 12-12-2008, 02:02 PM   #4
Luis Navarro
LQ Newbie
 
Registered: Dec 2008
Location: Brazil, Parana State, portuguese language.
Distribution: Fedora V8
Posts: 4

Original Poster
Rep: Reputation: 0
to Jonhsfine and to ErV many thanks.
I use: qmake -project
qmake
make
to compile.
Maybe I do those mess becouse I'm learning Linux and Qt alone, by myself,
in the try and repeat tecnique.
With your advice, I will improuve my programing thecnique.
I'll study your propositions and see.
Thanks again.
Luis

Last edited by Luis Navarro; 12-12-2008 at 02:21 PM.
 
  


Reply

Tags
c++, qt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
root servers and visibility jayeola Linux - Networking 3 08-21-2008 10:05 PM
People with limited visibility DC_FC79 Linux - Newbie 4 02-28-2008 02:07 PM
BASH visibility problem ZT13 Programming 4 12-24-2006 12:17 AM
Check application visibility 3saul Programming 9 02-13-2006 08:43 PM
gcc 4.0.2 and Elf Visibility SKelem Linux - Software 3 11-07-2005 04:12 PM


All times are GMT -5. The time now is 03:09 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration