Results 1 to 3 of 3

Thread: GUI crash using threads

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Post GUI crash using threads

    Hello,
    I am doing a programme which has to read continously information from a bus, and depending on what it read it will have to show some buttons and labels or anothers in the interface. But, I don't know why the GUI don't have time to refresh, or I don't know what is happening, in any case the GUI don't seem to change but variables did. Could you please give me a piece of advice or a suggestion? Sorry for my poor english. Thank you a lot in advance.
    Here is a piece of code I think it's representative of the problem.

    MainWindow.h:
    #INCLUDES...
    using namespace std;
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    class Thread *comunicacio;
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    private slots:
    void Emissio_estat(Pantalles estat_emes);

    private:
    Ui::MainWindow *ui;

    };

    MainWindow.cpp:

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

    qRegisterMetaType<Pantalles>();
    Thread* comunicacio = new Thread(this);

    QObject::connect(comunicacio, SIGNAL(Emissio_estat(Pantalles)), this,
    SLOT(Emissio_estat(Pantalles)),Qt::QueuedConnectio n);

    comunicacio->start(QThread::LowPriority);
    }

    void MainWindow::Emissio_estat(Pantalles estat_emes){
    int estat = estat_emes;
    switch (estat){
    case XXX:
    I use the functions PushButton.show(); Label.hide(); and others...
    break;
    case XXX: ....
    break;
    default:
    break;
    }

    Thread.h:
    class Thread : public QThread
    {
    Q_OBJECT
    public:
    explicit Thread(QObject *parent = 0);
    Thread *comunicacio;
    QMessageBox *informacio_1, *informacio_2;


    protected:
    virtual void run();

    signals:
    void Emissio_estat(Pantalles);
    };


    Thread.cpp:

    void CAN_Thread::run(){

    DECLARATION & INITIALIZATION OF VARIABLES;

    forever{
    nbytes = read(data);

    if (data != 0x00)
    {
    switch (data)
    {
    case xxxx:
    emit Emissio_estat(Pantalles);
    break;
    case xxxx:
    emit Emissio_estat(Pantalles);
    break;
    default:
    break;
    }
    }
    }
    }
    Last edited by mairimmart; 13th November 2013 at 11:27. Reason: reformatted to look better

Similar Threads

  1. using two threads
    By duma in forum Newbie
    Replies: 2
    Last Post: 18th August 2011, 16:58
  2. Qt Threads vs Native Threads performance
    By StackOverflow in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2010, 12:14
  3. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 03:59
  4. Crash while using threads
    By Luc4 in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2010, 12:19
  5. QGraphicsItem + Threads = Crash ?
    By medved6 in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2009, 04:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.