Threads
-
HI
"Go":http://lmgtfy.com/?q=QThread -
There are many different ways to use threads in Qt. Here is an overview:
-
hi sir..
I have seen threads in net but am not able understand hoe to use ...after all search i cme to knw writing a thred like this.Mainwindow .cpp
QThread *thread = new QThread(this);
thread->start();
connect(thread,Signal(started()),this,Slot(SerialportRead()));void MainWindow::SerialportRead()
{
//perform the serial port coomunication reading operation();}
In this way i have created the thread ,but am unable to receive any response.Please help me ..
-
Hi area 51, please have a look at this project
http://kde-apps.org/content/show.php/QtComPort?content=142378
you can see how I can read and manage data from serial port. -
I really, truly recommend this site to get idea of Qt threads:
"http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/best regards,
poorBob -
my code is :
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QThread>
#include <QPushButton>
#include <QDebug>
#include <QTimer>
QThread *mthread ;
QTimer *mtimer ;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->pushButton_color1->setAutoFillBackground(true);
ui->pushButton_color2->setAutoFillBackground(true);
ui->pushButton_color1->setStyleSheet("background-color : rgb(0, 255, 0)");mtimer = new QTimer(this); mthread = new QThread(this); connect(mthread,SIGNAL(started()),this,SLOT(ReadData())); connect(mtimer,SIGNAL(timeout()),this,SLOT(TimerData())); mtimer->start(100);
}
void MainWindow::ReadData()
{
while(1)
{
Serial();
}
}void MainWindow::Serial()
{for(int i=0;i<5;i++) { qDebug()<<"BBB:" <<i; } ui->pushButton_color2->setStyleSheet("background-color : rgb(0, 255, 0)");
}
void MainWindow::TimerData()
{
mtimer->stop();
mthread->start();}
MainWindow::~MainWindow()
{
delete ui;
}on intialy one button is geting coloured, but when i place the other button in threads that is not geting color ,please help me.
-
A small example of threading is provided "here":http://qt-project.org/forums/viewthread/26067
have a look at the last entry.