Results 1 to 10 of 10

Thread: How to not show widget

  1. #1
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default How to not show widget

    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

  2. #2
    Join Date
    Jun 2010
    Posts
    18
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to not show widget

    Take a look at QWidget::hide

  3. #3
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to not show widget

    What about removing the line 'client.show()'... ?
    !sirius

  4. #4
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to not show widget

    Quote Originally Posted by gQt View Post
    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.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to not show widget

    you can exclude gui by -

    QT -= gui

    in the pro file

  6. #6
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: How to not show widget

    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?

  7. #7
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: How to not show widget

    Quote Originally Posted by gQt View Post
    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.
    Qt Code:
    1. class Client: public QObject
    2. {
    3. Q_OBJECT
    4. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: How to not show widget

    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.

  9. #9
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to not show widget

    Quote Originally Posted by gQt View Post
    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:
    Qt Code:
    1. while(true)
    2. {
    3. QApplication::instance()->processEvents();
    4. QApplication::instance()->sendPostedEvents();
    5. }
    To copy to clipboard, switch view to plain text mode 

  10. The following user says thank you to amoswood for this useful post:

    gQt (10th June 2010)

  11. #10
    Join Date
    Feb 2008
    Posts
    36
    Thanks
    4

    Default Re: How to not show widget

    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.

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 19:42
  2. How to show thw widget in center?
    By sudhansu in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2010, 06:51
  3. How to show the widget?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 09:43
  4. how to show richtext and icons in one widget in QT2
    By pencilren in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2007, 11:30
  5. How to show a window widget...
    By agent007se in forum Newbie
    Replies: 3
    Last Post: 20th July 2006, 11:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.