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. MainWindow does not have a type

MainWindow does not have a type

Scheduled Pinned Locked Moved General and Desktop
3 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.
  • B Offline
    B Offline
    badzie
    wrote on last edited by
    #1

    In my application I'm trying to send some values from a thread to the main GUI for updating the values of a spinbox.

    The following is my code:
    ProcessThread.h
    @
    #ifndef PROCESSTHREAD_H
    #define PROCESSTHREAD_H

    #include<QtGui>
    #include<QThread>
    #include<QString>
    #include<QObject>
    #include"mainwindow.h"

    class ProcessThread : public QThread
    {
    Q_OBJECT
    public:
    MainWindow m;
    explicit ProcessThread(QObject *parent = 0);
    void run();

    signals:
    void SendStoredTempValues(int temp1,int temp2,int temp3);
    public slots:
    void WriteFileToSD();
    void WriteFileToUSB();
    void LoadValuesFromUSB();
    void Store_Temperatures(QByteArray temp);
    private:

    };

    #endif // MYTHREAD_H

    @

    ProcessThread.cpp
    @

    #include "ProcessThread.h"
    #include<QtCore>--
    #include<QDebug>
    #include<QDebug>
    QByteArray Write_Values;

    void ProcessThread::WriteFileToSD()
    {
    int i;
    QString OutputDirectory="/home/nithin";
    QString Filename="newFile.txt";
    QFile file(OutputDirectory+"/"+Filename);
    file.open(QIODevice::WriteOnly | QFile::WriteOnly);
    QTextStream out(&file);
    for(i=0;i<3;i++)
    {
    out<<(qint32)Write_Values[i];
    out<<';';
    }
    file.close();

    }
    int temp1,temp2,temp3;
    void ProcessThread::LoadValuesFromUSB()
    {
    int k=0;

    QString OutputDirectory="/media/SSTPL_2GB";
    QString Filename="newFile.txt",f1,f2,f3;
    bool ok;
    QFile file&#40;OutputDirectory+"/"+Filename&#41;;
    file.open(QIODevice::ReadOnly | QFile::ReadOnly);
    QByteArray file_read=file.readAll();
    while(file_read[k]!=';')
    {
        f1=f1+file_read[k];
    
        k++;
    }
    k++;
    while(file_read[k]!=';')
    {
        f2=f2+file_read[k];
    
        k++;
    }
    k++;
    while(file_read[k]!=';')
    {
        f3=f3+file_read[k];
    
        k++;
    }
    temp1=f1.toInt(&ok,10);
    temp2=f2.toInt(&ok,10);
    temp3=f3.toInt(&ok,10);
    
    
    emit SendStoredTempValues(temp1,temp2,temp3);
    connect(this,SIGNAL(SendStoredTempValues(int,int,int)),&m,SLOT(ValuesFromUSB(int,int,int)));
    

    }
    @

    If I try to include Mainwindow.h in my thread class I get the error as mainwindow does not have a type.

    I tried removing mainwindow.h from processthread.h and tried including in processthread.cpp and created as:
    Mainwindow m;(in ProcessThread.cpp instead of ProcessThread.h)

    This time, the code compiles but I get the error, as
    The inferior stopped because it received signal from operating system.

    How to access Mainwindow in thread for sending connecting the slot ?

    Thanks in advance!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Move the connect statement to your MainWindow. QWidget classes cannot be used outside of the GUI thread.

      Also, please check out "QThread documentation":http://qt-project.org/doc/qt-4.8/qthread.html - you are subclassing it needlessly.

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        badzie
        wrote on last edited by
        #3

        Oh! thank you.! stupid of me!

        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