[Qt-interest] Help with socketpair and QFiles

David Boosalis david.boosalis at gmail.com
Thu Apr 8 21:37:36 CEST 2010


Some may find this laughable, some pathetic, but I'd like to use a
SocketPair to communicate with from one QThread to another. I tried
QLocalSockets but it fails with a core dump once I get the volume of data
pumped up. This is on Linux,  any advise appreciated.

I do not get any of the read signals.  Here is what I have:

MainObject::MainObject(QObject *parent):QObject(parent)
{
  bool bstatus;
  int status;
  QByteArray ba;
  status =  socketpair(AF_LOCAL,SOCK_STREAM,0,socketFD);
  qDebug() << "Status of socketPair = " << status;
  // status returns 0 (good) when I run it.
  file = new QFile();

  bstatus = file->open(socketFD[1],QIODevice::ReadOnly);
  connect(file,SIGNAL(readyRead()),this,SLOT(readSocketSlot()));

  qDebug() << "Status of file for reading  = " << bstatus;
  // status returns true when I run it;
  myThread = new MyThread(socketFD[0],this);
  myThread->start();
  /*  Forget the signals, see if this work, and it does not
  while(int i=0<10) {
    ba = file->readAll();
    qDebug() << "Status of readAll = " << ba.size();
    sleep(1);
    i++;
  }
  */

}

void MainObject::readSocketSlot()
{
  qDebug() << "Here in readSocketSlot...";
  QByteArray ba = file->readAll();
}
/*****************************************************************************************

MyThread::MyThread(int FileID,QObject *p):
  QThread(p),fileID(FileID)
{
  bool bstatus;
  file = new QFile(this);

  bstatus = file->open(fileID,QIODevice::WriteOnly);
  qDebug() << "Status of file for writting  = " << bstatus;
  // returns true when I run it
}
void MyThread::run()
{
  int status;
  QDataStream out(file);
  for(int i=0;i<5;i++) {


    qDebug() << "I = " << i;
    status = write(fileID,"cat",3);
    qDebug() << "Status of write = " << status;
    // prints out 3 when I run it
    sleep(1);
    /*  want this code to work, but it failed to give me anything
    out << i;
    file->flush();
    sleep(1);
    */
  }
  exit();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100408/47e69432/attachment.html 


More information about the Qt-interest-old mailing list