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. QT + VTK + VS2008
Forum Updated to NodeBB v4.3 + New Features

QT + VTK + VS2008

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.0k 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.
  • M Offline
    M Offline
    Monicadiaz
    wrote on 10 Apr 2013, 04:31 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      sl.sy.ifm
      wrote on 10 Apr 2013, 06:02 last edited by
      #2

      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
      0

      1/2

      10 Apr 2013, 04:31

      • Login

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