Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QT + VTK + VS2008

    General and Desktop
    2
    2
    1865
    Loading More Posts
    • 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.
    • M
      Monicadiaz last edited by

      hi, well, i'm doing a project with qt, vtk, on VS 2008 C++

      the project consist on move a hand with a haptic device in these case is a glove. i have the serial communication working well, my problem is with qt i think. I want when i press a pushbutton , make the connection with my haptic device and the values that this send move the hand, this part is kind working, when i pressed the hand move , but the window of qt is stopped, totally blocked and i don't really know why, any body can help me?

      i have the next things

      THE MAIN

      #include <QtGui/QApplication>
      #include "leer.h"

      #include "SerialClass.h"

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      leer w;
      w.show();

      return a.exec();
      }

      A PART OF THE CODE OF LEER

      #include "leer.h"
      #include "ui_leer.h"
      #include "SerialClass.h"
      #include <tchar.h>

      #include "vtkPNGReader.h"
      #include <vtkRenderWindow.h>
      #include <vtksys/SystemTools.hxx>
      #include <vtkCamera.h>
      #include <QFileDialog>
      #include <QString>

      #include <QtGui/QMessageBox>
      #include "TSerial.h"

      leer::leer(QWidget *parent) : QMainWindow(parent),ui(new Ui::leer)
      {
      ui->setupUi(this);

      renderer = vtkRenderer::New();
      estilo = vtkInteractorStyleTrackballCamera::New();
      iren = vtkRenderWindowInteractor::New();
      renderer->SetBackground(0.043,0.18,0.58);
      renderer->SetBackground2(0,0,0);
      iren->SetInteractorStyle(estilo);

      cargar_mano();

      renderer->AddActor(articulaciones[0]);

      renderer->ResetCamera();

      ui->Renderizado->GetRenderWindow()->Render();
      ui->Renderizado->GetRenderWindow()->AddRenderer(renderer);
      ui->Renderizado->GetRenderWindow()->SetInteractor(iren);
      ui->Renderizado->GetRenderWindow()->Render();

      connect(ui->pushButton, SIGNAL(clicked()),SLOT (conexion()));

      }
      void leer::conexion()
      {
      // cout<<"Welcome to the serial test app!\n\n";
      Serial* SP = new Serial("\\.\COM3"); // adjust as needed

      if (SP->IsConnected())
      cout<<"We're connected";

      char incomingData[256] = "10"; // don't forget to pre-allocate memory
      printf("%s \n",incomingData);
      int dataLength = 4;
      int readResult = 0;

      while(SP->IsConnected())
      {
      readResult = SP->ReadData(incomingData,dataLength);
      printf("Bytes read: (-1 means no data available) %i \n",readResult);
      std::string test=incomingData;
      printf("%s \n",incomingData);
      //test = "";
      int value=atoi(test.c_str());
      printf("%i \n",value);
      articulaciones[12]->SetOrientation(value,0,0);
      ui->Renderizado->GetRenderWindow()->Render();
      Sleep(100);
      }

      }

      1 Reply Last reply Reply Quote 0
      • S
        sl.sy.ifm last edited by

        Qt is using just one thread for all GUI related things, this includes slots executed by GUI-events ... you put a endless loop("while(...Connected)") in the slot, so your code blocks the thread
        slot-function shouldn't contain code that lasts for more then some milliseconds ...

        You probably need to move the reading of serial-port to another thread ...
        ... or do it timer based (instead of sleeping and stay in one function you could use QTimer and have a function that only reads one time and then returns)

        1 Reply Last reply Reply Quote 0
        • First post
          Last post