thanks for u r replys
here is my header file.
//plot.h Include files are not specified to reduce the post size
{
Q_OBJECT
public:
th();
void run();
quint32 blocksize;
private slots:
void read_socket();
private:
};
{
Q_OBJECT
public:
PLOT();
private:
th t;
};
#endif /*PLOT_H_*/
class th : public QThread
{
Q_OBJECT
public:
th();
void run();
quint32 blocksize;
private slots:
void read_socket();
private:
QTcpSocket *socket;
};
class PLOT : public QMainWindow
{
Q_OBJECT
public:
PLOT();
private:
th t;
};
#endif /*PLOT_H_*/
To copy to clipboard, switch view to plain text mode
//plot.cpp
th::th() :blocksize(0)
{
}
void th::run()
{
socket->connectToHost("192.168.1.6", 9999);
connect(socket, SIGNAL(readyRead()), this, SLOT(read_socket()));
exec();
}
void th::read_socket()
{
if (blocksize == 0)
{
if (socket->bytesAvailable() < (int)sizeof(quint32))
return;
in >> blocksize;
}
}
PLOT::PLOT()
{
t.start();
//waiting here till the t.blocksize variable is getting filled but had not worked and never
//gets out of the loop,i have tried declaring the blocksize variable in the [B]th[/B]
//class as[B] volatile quint32 blocksize[/B] and even it has not worked.
//only [B]works[/B] when introduce a
//delay here as [B]QTest::qWait(3000);[/B]
while (t.blocksize == (qint32)0)
{
qDebug()<<" PLOT inside while "<<t.blocksize;
coloum=(int)(t.blocksize/360);
}
}
th::th() :blocksize(0)
{
}
void th::run()
{
socket=new QTcpSocket();
socket->connectToHost("192.168.1.6", 9999);
connect(socket, SIGNAL(readyRead()), this, SLOT(read_socket()));
exec();
}
void th::read_socket()
{
QDataStream in(socket);
if (blocksize == 0)
{
if (socket->bytesAvailable() < (int)sizeof(quint32))
return;
in >> blocksize;
}
}
PLOT::PLOT()
{
t.start();
//waiting here till the t.blocksize variable is getting filled but had not worked and never
//gets out of the loop,i have tried declaring the blocksize variable in the [B]th[/B]
//class as[B] volatile quint32 blocksize[/B] and even it has not worked.
//only [B]works[/B] when introduce a
//delay here as [B]QTest::qWait(3000);[/B]
while (t.blocksize == (qint32)0)
{
qDebug()<<" PLOT inside while "<<t.blocksize;
coloum=(int)(t.blocksize/360);
}
}
To copy to clipboard, switch view to plain text mode
where should i modify the code to work.
Bookmarks