Results 1 to 18 of 18

Thread: Serail Port GUI

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    62
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    43
    Thanked 1 Time in 1 Post

    Default Re: Serail Port GUI

    Hi Marcel,

    Thanks for the suggestion. Let me show the code that you suggested, and tell me if I misunderstood, or I'm doing anything wrong.



    Qt Code:
    1. // GUI Thread
    2. class GpsGui : public QTableWidget
    3. {
    4.  
    5. public slots:
    6. // Display data using QTableWidget
    7. void displayData( double, double, double );
    8. };
    9.  
    10. // GPS Read thread
    11. double lat, lon, utc;
    12. while( 1 )
    13. {
    14. // Read GPS data & modify lat, lon, utc
    15.  
    16. // send the data
    17. emit( lat, lon, utc );
    18. }
    To copy to clipboard, switch view to plain text mode 

    Is that code skeleton kind of right (both syntax and semantic)? But where should I do the connect( ) to connect the GPS Read thread's signal to the GpsGui's slot?

    Note GPS Read thread and GpsGui are in different files.

    Sorry if the code is just wrong..I'm trying to learn this.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: Serail Port GUI

    ALSO: You need to define a signal that you emit in the thread, like:
    Qt Code:
    1. //in thread definition:
    2. signals:
    3. void values( double, double, double );
    To copy to clipboard, switch view to plain text mode 
    Then you can do in the while loop:
    Qt Code:
    1. emit values( val1, val2, val3 );
    To copy to clipboard, switch view to plain text mode 
    Where do you create the thread? Is it in the Gui?
    If so, try this:

    Qt Code:
    1. connect( workerThread, SIGNAL( values( double, double, double ) ), this, SLOT( displayValues( double, double, double ) ) );
    To copy to clipboard, switch view to plain text mode 
    If it is not, then I suggest implementing the singleton pattern for your main window. Doing this you'll provide a GPSGui::Get() static method.

    You'll be able to do( before actually starting the thread):
    Qt Code:
    1. connect( workerThread, SIGNAL( values( double, double, double ) ), GPSGui->Get(), SLOT( displayValues( double, double, double ) ) );
    To copy to clipboard, switch view to plain text mode 
    Having said this, I assumed your thread is a QThread... Is it? Because if it isn't, you'll need to approach things differently...

    regards
    Last edited by marcel; 17th April 2007 at 20:11.

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

    ShaChris23 (17th April 2007)

Similar Threads

  1. Serial Port communication
    By mgurbuz in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2011, 03:38
  2. Replies: 6
    Last Post: 18th April 2007, 16:04
  3. list port of computer
    By manhds in forum Qt Programming
    Replies: 2
    Last Post: 12th March 2007, 10:04
  4. trayicon port to QT4
    By ykohn in forum Qt Programming
    Replies: 10
    Last Post: 21st April 2006, 16:11
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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
  •  
Qt is a trademark of The Qt Company.