Q:

QT ui not showing up when MainWindow initated from another class (not in the main function)

Is it possible to initiate the object of MainWindow in QT and call the show method from another class, for example inside a thread class constructor, and then create the thread object in the main function and start the thread?  It does not work for me (the ui flashes and disappears immediately).  Is there any way to fix it?  If not, how can I control buttons and other stuff from the thread.  How can I communicate between them (the thread and ui class) by exchanging data?  
My program looks like this.  Thread constructor:
#include "mainwindow.h"

void thread::thread(){
    MainWindow m;
    m.show();
}

and the main function:
int main(int argc,char *argv[]){
    QApplication a(argc,argv);
    thread t;
    t.start();
    return a.exec();
}

A:

You can do this, but before that you have to connect your MainWindow to the thread object.  You should never call from another thread than the GUI-thread functions that modify the GUI. 
The solution would be to use slots/signals.  All the communication from threads to the UI is always done with slots and signals. 
Below an example:
Create a signal in your Thread class called mySignal();
class Thread {

...

signals:
  void mySignal();

... 
}

and create a slot in your MainWindow
class MainWindow {

...

public slots:
 void ShowWindow();

..

}

Create a function in your MainWindow class called showWindow()
void MainWindow::ShowWindow() {

this->show();

}

Connect your thread to the MainWindow
connect(threadObject, &Thread::mySignal, this, &MainWindow::ShowWindow);

Call the slot from your thread with emit mySignal();
PS: Your application should be a widget application not console.