Results 1 to 13 of 13

Thread: Interconnect Qt application & External .cpp 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 Interconnect Qt application & External .cpp application!!!!

    Hello! Everybody,
    I am planning to design a GUI for an external .cpp application. I am using RedHat Linux with Qt3.3.3. I want user to select some data from GUI like int variable; string name; etc and then GUI should send this selected data as arguments to the external .cpp application for its calculation. And finally after calculations are over in external application i need to send the result to GUI for displaying it to the user.

    For example i have: -
    In Qt project: - i.) main.cpp ii.)gui.cpp iii.)gui.h
    In External application: - i.) MyProgram.cpp working using normal c++ headers & libraries.

    "MyProgram.cpp is not a part of the Qt project, its an external application"

    I will be obliged if suggested proper path/direction to do the desired work.

    Thanks very much in advance.

  2. #2
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    I don't know much about Qt 3 but I would suggest to use sockets for interprocess communication. Personally I use QUdpSocket to communicate between apps but they are both Qt 4 apps...
    C++ & AMD forever

  3. The following user says thank you to THRESHE for this useful post:

    Krish (28th February 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    there are various ways to do this.
    And it has nothing to do with Qt.
    Your best bet is probably using sockets - in that case you can use Qt socket classes.
    (you can also write you non gui applicatino with Qt)
    But shared memory and pipes are also options.
    You should decide which option to use by considering your implementation requirements.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Krish (28th February 2008)

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

    Lightbulb Re: Interconnect Qt application & External .cpp application!!!!

    Hello! high_flyer,
    Thanks for taking out ime & replying me. As you said in ur reply: -
    Your best bet is probably using sockets - in that case you can use Qt socket classes.(you can also write you non gui applicatino with Qt)
    Sorry to say but i didn't completely understand it. I took a look at QSocket class & its functions.

    Even if i use QSocket class for the purpose, how can i connect to host as the application runs on my very same PC? Also for connection how can i get "host" & "port" parameters?
    And after connecting i would be in the folder & how can i start MyProgram.cpp application? Also how could i send the arguments to specific functions in MyProgram.cpp application and get the result back?

    Thanks very much if shown or directed to an example as i am pretty new to Qt.
    Last edited by Krish; 28th February 2008 at 16:43.

  7. #5
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    Is it compulsory to use Qt 3 ?
    C++ & AMD forever

  8. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    @Krish:
    socket programming has nothing to do with Qt, except for the fact that Qt wraps that functionality too.
    However, since you are using Qt, have a look at the examples.
    In addition do a search in google for "socket programming C++ example" - you will get lots of information.

    Also, if there is no special reason to use Qt3, I would also recommend to use Qt4.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. The following user says thank you to high_flyer for this useful post:

    Krish (28th February 2008)

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

    Question Re: Interconnect Qt application & External .cpp application!!!!

    Hello! Threshe,
    Yes buddy i have to use the same to acheive it. But i am able to use Qt4 can you please broaden my info over how actually did you use QUdpSocket. I mean it just connects you to the host. How can you run the program, call its functions, send data, recieve data n all?
    OR can i use QProcess/QThread????

    Thanks in advance.
    Last edited by Krish; 28th February 2008 at 16:52.

  11. #8
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    I used QUdpSocket to transfer path for opening files like this
    Qt Code:
    1. QSocketListener::QSocketListener()
    2. : QObject(parent)
    3. {
    4. socket_ = new QUdpSocket();
    5. socket_->bind(QHostAddress::LocalHost, 40002);
    6. connect(socket_, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
    7. }
    8.  
    9. void QSocketListener::SendPath(QString filePath)//Send Data
    10. {
    11. socket_->disconnect();
    12. socket_->writeDatagram(filePath.toUtf8(), QHostAddress::LocalHost, 40002 );
    13. }
    14.  
    15. void QSocketListener::readPendingDatagrams()
    16. {
    17. QByteArray datagram;
    18. datagram.resize(socket_->pendingDatagramSize());
    19.  
    20. socket_->readDatagram(datagram.data(), datagram.size());
    21. QString path = datagram;
    22. emit openFile(path);
    23. }
    To copy to clipboard, switch view to plain text mode 
    I hope it helps
    C++ & AMD forever

  12. The following user says thank you to THRESHE for this useful post:

    Krish (28th February 2008)

  13. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    UDP is not recommended, since this protocol can't deliver you any security regarding the data sent/received as TCP/IP does.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  14. #10
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    I know but for my purpose it works well
    C++ & AMD forever

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

    Thumbs up Re: Interconnect Qt application & External .cpp application!!!!

    Hello! high_flyer,
    Thanks for directing me to this stuff.
    Quote Originally Posted by high_flyer View Post
    However, since you are using Qt, have a look at the examples.
    Its really a nice class to be used for communicating between more programs. But it has used 2 QT application/program for communicating between them whereas i have one Qt & other Non-Qt applications/programs, because of which i have few questions to ask like: -

    1.) Can i simply include the required Qt header files in MyProgram.cpp to create socket, handle connection & transfer data as it is Non-Qt .cpp file? or will it create problems like can't find the required libraries or not compatible?

    2.) Also how can i send more than one type of data say int, str,.... at the same time through the same socket and recieve it properly to process them in reciever program's function? Just as we send arguments to the functions!!!!

    3.) As you had said in previous reply that i can write MyProgram.cpp in Qt itself, how as it does its own work using different libraries & all?

    Thanks again in advance.
    Last edited by Krish; 29th February 2008 at 12:47.

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

    Lightbulb Re: Interconnect Qt application & External .cpp application!!!!

    Hello! Threshe,
    Thanks for showing me coded example. But i would like to ask few things more like: -
    1.) As my both applications are running on the same machine, will the parameter "host"=localhost or something else? Anyway if the both of them were on different PC's how can i get the host name properly?

    2.)Please let me know as you used port 40002 for i/o connection, which should be used by me or from where to get that info?

    Thanks again in advance.
    Last edited by Krish; 29th February 2008 at 12:31.

  17. #13
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Interconnect Qt application & External .cpp application!!!!

    Quote Originally Posted by Krish View Post
    1.) As my both applications are running on the same machine, will the parameter "host"=localhost or something else? Anyway if the both of them were on different PC's how can i get the host name properly?
    For my purposes I've used only localHost so I cannot help you with other hosts sorry...
    Quote Originally Posted by Krish View Post
    2.)Please let me know as you used port 40002 for i/o connection, which should be used by me or from where to get that info?
    Honestly I've just picked a random port number
    C++ & AMD forever

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 11:12
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 23:04

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.