Results 1 to 1 of 1

Thread: Qthread Problem

  1. #1
    Join Date
    Jan 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Qthread Problem

    Hello friends,
    I have created my custom thread class called SnifferThread. What i am doing in this thead is sniffing IP packets and whenever a packet is sniffed i am emitting a signal called gotPacket.
    Qt Code:
    1. void mycustomthread::run()
    2. {
    3. while(!stopped)
    4. {
    5. // i here call the function used to grab packets
    6. function_for_grabbingpackets()
    7. }
    8. stopped = false;
    9. }
    10.  
    11. //function called from mainwindow when the stop button is clicked
    12. void mycustomthread::stop()
    13. {
    14. stopped = true;
    15. qDebug()<<"The thread has stopped running";
    16. }
    17. void function_for_grabbingpackets()
    18. {
    19. //logic for grabbing packets
    20. // when a packet is arrived emit gotPacket()
    21. }
    To copy to clipboard, switch view to plain text mode 

    my problem is that i want to insert a new row to my custom QTableWidget class whenever gotPacket() signal is emmited.
    i know that i have to connect them in my main windows thread using signals and slots which i am doing like given below

    connect(mycustomthread, SIGNAL(gotPacket()), mycustomQItemWidget, slot(addNewRow()))

    in the add new row i am adding a new row like this
    void mycustomQItemWidget::addNewRow()
    {
    int count = rowCount();
    insertRow(count);
    }

    now what i wnt is that i want to pass the captured packet to my customtable so that i can fill the columns of my newly inserted row with the information i have got.
    Please help me for how to achieve this. should i use signal and slots with parameters if yes how??
    Last edited by wysota; 2nd March 2009 at 08:31. Reason: missing [code] tags

Similar Threads

  1. Replies: 0
    Last Post: 26th September 2008, 21:33
  2. QThread problem
    By MrShahi in forum Qt Programming
    Replies: 6
    Last Post: 15th July 2008, 12:28
  3. QThread and PostgreSQL - a problem
    By Lesiok in forum Qt Programming
    Replies: 12
    Last Post: 9th April 2008, 09:07
  4. Problem with QTcpSocket in QThread
    By Raistlin in forum Qt Programming
    Replies: 8
    Last Post: 6th October 2007, 12:23
  5. Replies: 3
    Last Post: 15th April 2007, 19:16

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.