PDA

View Full Version : Qthread Problem



sroger
2nd March 2009, 07:35
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.

void mycustomthread::run()
{
while(!stopped)
{
// i here call the function used to grab packets
function_for_grabbingpackets()
}
stopped = false;
}

//function called from mainwindow when the stop button is clicked
void mycustomthread::stop()
{
stopped = true;
qDebug()<<"The thread has stopped running";
}
void function_for_grabbingpackets()
{
//logic for grabbing packets
// when a packet is arrived emit gotPacket()
}

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??