Qt startup function
-
How do you define as soon as the program starts?
If the event loop being active isn't required, call the function from main() before QCoreApplication::exec(). If the event loop is required, post an event prior to exec(), and then implement event() or eventFilter() somewhere to receive it. One way to post an event is with a QTimer with duration = 0.
-
What do you mean as soon as Qt program starts ? Is it when you create the QCoreApplicaiton/QApplication/QGUIApplication object ? You can subclass QCoreApplication and write what do you want in constructor
-
I want to hide some pushbuttons when the program opens. but when I put it in main it gives me the error
'ui' was not declared in this scope
ui->pushButton->setVisible(false);
^it is in main.cpp and I am including
#include "Profile.h"
#include <QApplication>
#include <QtGui>what am I doing wrong
EDIT:
also when I call the function from main it says
error: cannot call member function 'void Profile::startup()' without object
Profile::startup();
^ -
@ Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->pushButton->setVisible(false);
ui->radioButton->setVisible(false);
}@You can set in the constructor itself. If show or hide is based on some condition, you can define different method in your class with argument, before show you can call method. Inside the method you can hide or show whatever you want.
-
As you observer, code is in the constructor. This code does not go in main.cpp. It goes to source file