Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Freezed window
Forum Updated to NodeBB v4.3 + New Features

Freezed window

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca.paolini
    wrote on last edited by
    #1

    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));
    }
    

    }
    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca.paolini
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • B Offline
          B Offline
          butterface
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca.paolini
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved