Freezed window



  • Hi all,
    is my first time in a form so, if I made mistakes, sorry...
    I wrote a simply program that get images from udp channel and show them in my MainWindow, also I show some counter.
    The program work fine and fast but MainWindows is not sizable, is not movable, clicking button nothing happens.

    Now I try to explain my problem:
    there are 2 classes, one for mainwindows and one for udp channel; these classes are connected by two signals and two slots

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Camera *camera = new Camera();
    camera->show();

    udpCameraManager *cameraManager = new udpCameraManager();
    
    QObject::connect(cameraManager,SIGNAL(ImageReadySignal(QByteArray*)),camera,SLOT(DoDrawImage(QByteArray*)));
    
    QObject::connect(camera,SIGNAL(Ready(void)),cameraManager,SLOT(GetImage(void)));
    
    camera->cameraManager = cameraManager;
    return a.exec();
    

    }
    @

    Clicking a button the first GetImage happen and the download starts. GetImage is:

    @ void GetImage()
    {
    QByteArray Data;
    Data.append("Hello from UDP");

      // Sends the datagram datagram
      // to the host address and at port.
      // qint64 QUdpSocket::writeDatagram(const QByteArray & datagram,
      //                      const QHostAddress & host, quint16 port)
      QHostAddress RemoteHost;
      RemoteHost.setAddress("10.2.128.2");
    
      connect(socket, SIGNAL(readyRead()), this, SLOT(slotReadData()));
    
      socket->writeDatagram(Data, RemoteHost, 11000);
    

    }
    @

    then slotReadData emit ImageReadySignal that is connected to DoDrawImage; DoDrawImage create image, call QWidget::repaint() and emit Ready signal; Ready signal is connected to GetImage.
    My paintEvent is:

    @void Camera::paintEvent(QPaintEvent *event)
    {
    if(!DoIt)
    return;
    QPainter painter(this);

    if (!image.isNull())
    {
        painter.drawImage(10,10,image);
        ImgCounter++;
        double difference = (time.elapsed() / 1000);
    
        QRect rect = QRect(670, 140, 180, 20);
        painter.drawText(rect,Qt::AlignLeft,"difference: " + QString::number(difference,'f',2));
    
        rect = QRect(670, 170, 180, 20);
        if(difference > 0)
        {
            double fps = (double)ImgCounter/(double)difference;
            painter.drawText(rect,Qt::AlignLeft,"fps: " + QString::number(fps,'f',2));
        }
        rect = QRect(670, 200, 180, 20);
        painter.drawText(rect,Qt::AlignLeft,"Images: " + QString::number(ImgCounter));
    }
    

    }
    @



  • For me that sounds like an infinite loop of your signal and slot connections. Is that possible?



  • Yes it is, I need to download and show continuosly, but I dont know how to solve the freeze, I'm new on Qt programming.
    Thanks



  • Your slots should do as little work as possible because staying in a slot blocks the event queue. You can use QThread for example to download the image. When it is finished call a slot to display it. If it fits your needs you can also use QTimer to update you UI every x milliseconds.
    There are a few possibilities to periodically update your UI but a major rule is to never block the event queue.



  • OK,
    I'll try it and I'll answer as soon as possible.
    Thanks alot for your suggestions.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.