Results 1 to 2 of 2

Thread: GUi or Not GUI - that is the question

  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question GUi or Not GUI - that is the question

    Hello,
    I need to know what call I can make to determine whether I'm in a GUI or non-GUI thread. I have a utility function that displays a message that tells me whether my signals and slots really exist. This helps me know if I've incorrectly specified a signal or slot. The only problem is, when I go to display the message via QMessageBox::information(), if I'm in a non-gui thread I get the message that I can't create a GUI element in a non-gui thread.

    How can I tell?

    Here's the code

    bool Util::myConnect(const QObject *from, const char *signal, const QObject *to, const char *slot)
    {
    if (!connect(from, signal, to, slot))
    {
    QString text = QString (tr("QT connect() API failed\nFrom class: %1\n\tSIGNAL: '%2\nTo class: %3\n\tSLOT: '%4'\n"))
    .arg(from->metaObject()->className())
    .arg(signal)
    .arg(to->metaObject()->className())
    .arg(slot);
    // This doesn't work if we are not in the main GUI thread
    // How can I check to see if we are in the GUI thread?
    **** QMessageBox::critical(NULL, tr("Run-time coding API Error"), text);
    return false;
    }
    return true;
    }

    - BRC

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: GUi or Not GUI - that is the question

    Qt Code:
    1. if (QThread::currentThread() == qApp->thread())
    2. {
    3. // this is the main thread
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    bruccutler (23rd February 2007)

Similar Threads

  1. QTableView Question
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2007, 19:02
  2. Question about using the QextSerialPort~
    By coffeemorphism in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2007, 15:16
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 16:34
  4. Example code and metaObject question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 12th January 2007, 19:34
  5. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 15:38

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.