Qt, new object for MainWindow, app crash,how to emit finished() signal

571 views Asked by At

In main class MainWindow I have method which sets setEnabled("false") for each button, when the application is downloading. In other class "Download" I have method responsible for downloading. There is sth like this if ( uRet == S_OK ) and after download I would like to setEnable("true") for each button, but I can't run method from MainWindow in this if() 'couse I get "QWidget: Must construct a QApplication before a QPaintDevice".

How to run the method from the MainWindow class in the Download Class, or refer to these buttons from the Download Class.

edit:// I need to emit signal

class downloaded : public QObject
{
    Q_OBJECT
public:
    void test3();
signals:
    void changeEnabled();
};

void downloaded::test3(){
    emit changeEnabled();

}
class MainWindow : public QMainWindow{
        Q_OBJECT

public:
       ...
public slots:
        void ONchangeEnabled();
}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    downloaded test_object;

   connect(&test_object, SIGNAL(changeEnabled() ), this, SLOT(ONchangeEnabled() ) );

   ui->setupUi(this);           
   setupUI();                  

}

void MainWindow::ONchangeEnabled(){
    ui->actionDL->setEnabled(true);
}

and in function which downloads files I have sth like that.

downloaded obiekt;
...
     if ( uRet == S_OK )
        {
             obiekt.test3(); return 0;
        }
        else {
             obiekt.test3(); return 1; 
        }

But nothing happens, what am I doing wrong.

1

There are 1 answers

1
Tatu Lahtela On

Signals are always object and not class level. You are not connecting to the instance of "downloaded" object you are trying to listen signals to. The one you connect to is created and deleted in the MainWindow constructor, and has no relevance to the one created in the second code block.