Results 1 to 8 of 8

Thread: function 'connect' always look super class for slots.

  1. #1
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default function 'connect' always look super class for slots.

    Hello, I'm a newbie to qt programming.
    These days, I write a simple image viewer with qt4 on WinXP. My code mainly consists of MyWindow derived from QMainWindow, MyImageWidget derived from QWidget.

    Creating objects and showing images are all good but there's a problem with SIGNAL-SLOT connection.

    Menus and actions are made in MyWindow::createMenu() before that is shown.

    QMenu *fileMenu = menuBar()->addMenu("File");
    openAction = fileMenu->addAction("Open");
    connect(openAction, SIGNAL(triggered()), this, SLOT(fileOpen()));
    return true;

    Of course, openAction is a member variable of MyWindow and fileOpen() is a member function of the same class.

    When I run the compiled binary, everything seem to be good, but the menu does not work and there's a error message in console window like this:

    "Object::connect: No such slot QMainWindow::fileOpen()""

    In my opinion, Object::connect function tries to find 'fileOpen' function in QMainWindow. But that is defined in the child class!!

    I took some alternatives but I could not find any solution.


    Thanks in advance.


    Intaek.

  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: function 'connect' always look super class for slots.

    Hi, add Q_OBJECT macro to the declaration of the class and re-run qmake to re-generate required steps for moc in the makefile.
    Last edited by jpn; 12th March 2007 at 07:40. Reason: Fixed the broken link
    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: function 'connect' always look super class for slots.

    Thanks, but I tried that. But when I add that macro, there are some link errors. What library should I add?

    error LNK2001: "public: virtual struct QMetaObject const * __thiscall TVMainWindow::metaObject(void)const " (?metaObject@TVMainWindow@@UBEPBUQMetaObject@@XZ) tvmainwindow.obj
    error LNK2001: "public: virtual void * __thiscall TVMainWindow::qt_metacast(char const *)" (?qt_metacast@TVMainWindow@@UAEPAXPBD@Z) tvmainwindow.obj
    error LNK2001: "public: virtual int __thiscall TVMainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@TVMainWindow@@UAEHW4Call@QMetaObject @@HPAPAX@Z) 외부 기호를 tvmainwindow.obj

  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: function 'connect' always look super class for slots.

    Quote Originally Posted by Intaek Lim View Post
    But when I add that macro, there are some link errors. What library should I add?
    That's why I suggested re-running qmake. The required moc steps are missing. For signals and slots, an auto-generated piece of code must be compiled and linked. Adding the Q_OBJECT macro and re-running qmake takes care of this.

    But, I see you are using Visual Studio. Do you have a commercial license and the Visual Studio integration? I think the commercial integration should take care of detecting an added Q_OBJECT macro automatically, but if you are using an open source version and the community patches, you might need to regenerate the Visual Studio project file or something.
    J-P Nurmi

  5. #5
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: function 'connect' always look super class for slots.

    Thank for your reply, but I don't know to qmake in WinXP environ. with VS2005.

  6. #6
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: function 'connect' always look super class for slots.

    Quote Originally Posted by Intaek Lim View Post
    Thank for your reply, but I don't know to qmake in WinXP environ. with VS2005.
    Create a seperate *.h and *.cpp file. Put your declarations in *.h and definations in *.cpp. Use Q_OBJECT macro defore defining your constructor in *.h file and before public specifier. Hit the "moc" button provided with vs-integration(which you can see at top after you have installed qt properly).

    This should solve the problem.

  7. #7
    Join Date
    Jul 2006
    Location
    Poprad/Prague
    Posts
    33
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: function 'connect' always look super class for slots.

    I'm not really sure, if I know what the problem exactly is, but some suggestions:

    You should put Q_OBJECT macro inside your class and re-run qmake, but one other question crossed my mind: Did you put your function in 'public/private slots' section of the class?

  8. #8
    Join Date
    Mar 2007
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: function 'connect' always look super class for slots.

    if your MyWindow has more than one parent make sure that QMainWindow listed first:

    class MyWindow: public QMainWindow,public AnyOtherParents

    otherwise moc will parse it incorrectly.

Similar Threads

  1. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 23:04
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 13:52
  3. Problems calling C function in C++/Qt class
    By Rayven in forum General Programming
    Replies: 2
    Last Post: 2nd June 2006, 22:32
  4. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 09:52
  5. virtual overloaded functions and base class function call...
    By nouknouk in forum General Programming
    Replies: 7
    Last Post: 11th March 2006, 22:26

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.