PDA

View Full Version : How to not show widget



gQt
8th June 2010, 17:19
Hi all,

I want my application to not show any widget. The program contains a class (Client) which is a subclass of QDialog.

Client::Client(QWidget *parent,QString iptest,QString dbName,QString sensorNr,QString sensorNr2)
: QDialog(parent)

In main.cpp the program is started with

Client client(parent,QString::fromLocal8Bit(argv[1]),QString::fromLocal8Bit(argv[2]),QString::fromLocal8Bit(argv[3]),QString::fromLocal8Bit(argv[4]));
client.show();
return client.exec();

I have failed to find an option in qmake to suppress GUI. I guess it is possible to remove the links to QtGui in the makefile? I am using Qt-4.5.3 on ubuntu 8.0.4.
Any help is deeply appreciated, thanks in advance!

gQt

jnadelman
8th June 2010, 17:29
Take a look at QWidget::hide

sirius
8th June 2010, 18:15
What about removing the line 'client.show()'... ?

amoswood
8th June 2010, 18:44
I want my application to not show any widget
The real way to do this is to instansiate your QApplication using QApplication(argc, argv, false). Doing so will ensure that no GUI system is available for your application. However, no class will be able to inherit or use any class which is defined in the QtGui module.

aamer4yu
8th June 2010, 20:55
you can exclude gui by -

QT -= gui

in the pro file

gQt
9th June 2010, 10:36
Thanks for answering!
I have already tried hide() with no success.
The program has a QTimer. Signal/Slot is required to use the connect-function,which means that my class Client has to inherit QObject:
in the .h file:
class Client: public QDialog
{
Q_OBJECT

To inherit Q_OBJECT, Client has to subclass a GUI-class QDialog, QWidget or QMainWindow. If I try to include the QT=-GUI in the .pro-file or QApplication app(argc,argv,false) in the main.cpp the program ceases to work. Is it possible to subclass a noneGui class instead of QDialog?

amoswood
9th June 2010, 15:18
Is it possible to subclass a noneGui class instead of QDialog?
Both QObject and QTimer are contained in the QtCore module. You can simply inherit your class from QObject instead.

class Client: public QObject
{
Q_OBJECT
}

gQt
10th June 2010, 10:07
Thanks amoswood!
I have already tried to subclass QObject. The problem is then that QObject has no exec(), so the program can not have return Client.exec() in main.cpp.

amoswood
10th June 2010, 14:36
I have already tried to subclass QObject. The problem is then that QObject has no exec(), so the program can not have return Client.exec() in main.cpp.
I don't know what you are doing in your Client class, but you can work around the exec() function with the code or the Qt class QEventLoop:


while(true)
{
QApplication::instance()->processEvents();
QApplication::instance()->sendPostedEvents();
}

gQt
10th June 2010, 20:59
The class QEventLoop solved the problem, thanks :) Client can subclass QEventLoop, and QEventLoop has also an exec() function, so it is still possible to have the Client.exec() in main.