Results 1 to 5 of 5

Thread: Connect question...

  1. #1
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Connect question...

    Hi Folks,

    I am having a problem getting messages between my classes. My basic program structure is like this: Main creates a MyApp::QApplication, MyApp creates a MyWindow::QMainWindow. In MyApp I have an About().

    My Problem is I don't know how to connect the QAction created for the menu entry in MyWindow to the MyApp::About()? I have been trying to do something like this:

    connect(AboutAction,SIGNAL(triggered()),MyApp,SLOT (about()));

    But that obvisouly won't work as MyWindow doesn't know about MyApp

    Can anyone help me please?

    Thanks

    McCall

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

    Default Re: Connect question...

    Try QApplication::instance() (or qApp) in place of MyApp in the connect statement.
    J-P Nurmi

  3. #3
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Connect question...

    Thanks for the quick reply, I had looked at the examples and tried qApp, but hadn't included the QApplication header so the build failed I have now added:

    #include <QApplication>

    and change my connect to this:

    connect(AboutAction,SIGNAL(triggered()),QApplicati on::instance(),SLOT(About()));

    My method is declared like this:

    private slots:
    void About();

    and my method is this:

    void PlaygroundApplication::About()
    {

    QMessageBox::about(mainPlaygroundWindow, tr("About SDI"),
    tr("The <b>SDI</b> example demonstrates how to write single "
    "document interface applications using Qt."));
    }

    Yet, I never get to About().

    Can you see something that I am doing wrong?

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

    Default Re: Connect question...

    Does PlaygroundApplication declaration contain Q_OBJECT macro?

    Edit: Oh, and in case it doesn't, make sure the corresponding header file is listed and .pro file and qmake is re-run after adding the macro.
    Last edited by jpn; 20th June 2007 at 17:52. Reason: updated contents
    J-P Nurmi

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

    McCall (20th June 2007)

  6. #5
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Connect question...

    Thanks!

    Q_OBJECT and a qmake clean did the trick!

Similar Threads

  1. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  2. Replies: 5
    Last Post: 28th August 2006, 14:36
  3. question on connect
    By mickey in forum Newbie
    Replies: 6
    Last Post: 14th June 2006, 13:50

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
  •  
Qt is a trademark of The Qt Company.