Results 1 to 4 of 4

Thread: Can we call functions of other process in Qt GUI application?

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Can we call functions of other process in Qt GUI application?

    Hello! Friends,
    I have a square .cpp program for squaring the given number but it is another pure .cpp file called "square.cpp" file containing no Qt classes or headers but which i have placed in the same GUI project with other files. Now what i am planning is to call the "square_of(int i)" function from square.cpp file in my GUI .cpp file, just by including the square.h file in GUI .cpp file and get the result of squaring in my GUI. Is it possible????

    If yes how? and if not any other solution?

    I will be obliged if replied.-----> Thanks in Advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Can we call functions of other process in Qt GUI application?

    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Can we call functions of other process in Qt GUI application?

    Hello! jpn,
    Thanks for replying and showing me that site. But Sir i know C++ programming, what i dont know is can we call that function from GUI .cpp file or not. Sir it is serious!!!!

    Below are the files: -
    Qt Code:
    1. /////////-------Square.h---------///////////
    2. #ifndef SQUARE_H
    3. #define SQUARE_H
    4.  
    5. #include<iostream>
    6.  
    7. class Square
    8. {
    9. public:
    10. Square();
    11. int Square_of(int);
    12. }
    13. #endif
    14. ////////----End of file-------/////////
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ///////-----Suare.cpp------//////////
    2. #include<square.h>
    3.  
    4. int Square::Square_of( i )
    5. {
    6. return i*i;
    7. }
    8. /////////-------End of file------/////////
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ////////-------testform.ui.h 'which is GUI form's file'------//////////
    2. #include<square.h>
    3.  
    4. void testForm::square()
    5. {
    6. int i = inputLineEdit->text().toInt();
    7. int sq = Square_of(i);
    8. resultLineEdit->setText(QString::number(sq,10));
    9. }
    10.  
    11. void testForm::init()
    12. {
    13. resultLineEdit->setText("2");
    14. resultLineEdit->selectAll();
    15. }
    16. ///////------End of file-------///////////
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /////////-------main.cpp 'which is GUI's execution file---------/////////
    2. #include <qapplication.h>
    3. #include "test1form.h"
    4.  
    5. int main( int argc, char ** argv )
    6. {
    7. QApplication a( argc, argv );
    8. test1Form w;
    9. w.show();
    10. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    11. return a.exec();
    12. }
    13. ////////------End of file-----/////////
    To copy to clipboard, switch view to plain text mode 

    When i tried to execute it like by using qmake & make it showed me some errors: -
    square.cpp:5: error: extraneous `int' ignored
    square.cpp:5: error: `Square Square::Square_of' is not a static member of `class Square'
    square.cpp:5: error: `i' was not declared in this scope
    square.cpp:6: error: expected `,' or `;' before '{' token
    make: *** [.obj/square.o] Error 1
    Can you please let me know what is causing these error's.

    I will be obliged if helped.-------->Thanks in Advance.
    Last edited by jpn; 4th March 2008 at 08:28. Reason: missing [code] and [quote] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Can we call functions of other process in Qt GUI application?

    First of all, this is a very basic C++ problem and has nothing to do with Qt. Secondly, this is still a very basic C++ problem and I really really recommend reading a C++ book.

    It's an unfortunate fact that you must know the basics of the programming language before you start working with a toolkit like Qt. Some language bindings might be easier to start with but especially C++ requires some knowledge. The problem here is that unless you make the method static, you must instantiate a Square object to be able to call its member function. Oh, and the syntax is still not correct even if it was static...
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    Krish (4th March 2008)

Similar Threads

  1. Module to process application parameters
    By Opilki_Inside in forum General Programming
    Replies: 4
    Last Post: 8th February 2007, 23:26
  2. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 21:26

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.