Results 1 to 3 of 3

Thread: GUI crash using threads

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

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GUI crash using threads

    That looks kind of OK.
    Can you make a qDebug() output in MainWindow::Emissio_estat() and see if it gets called?

    Btw, the Forum has code tags for posting code snippets. code and /code in square brackets

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    mairimmart (27th November 2013)

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

    Default Re: GUI crash using threads

    Thank you very much for your replay, and sorry for the late of mine.
    Finally I've fixed the mistake, it was about another part of the code...
    Eventhough thanks a lot!

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.