Results 1 to 5 of 5

Thread: error No such slot QMainWindow::open()

  1. #1
    Join Date
    Aug 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Symbian S60

    Unhappy error No such slot QMainWindow::open()

    hi,

    When i am running the following program i am getting following error
    Object::connect: No such slot QMainWindow::open()
    pls help me to resolve this one


    my win.h Header File
    Qt Code:
    1. #ifndef WIN_H
    2. #define WIN_H
    3. #include<QtGui>
    4. class win : public : QMainWindow
    5. {
    6. public:
    7. win();
    8. private slots:
    9. void open();
    10. private :
    11. };
    12. #endif
    To copy to clipboard, switch view to plain text mode 
    my win.cpp file

    Qt Code:
    1. #include"win.h"
    2. #include<QtGui>
    3. win::win()
    4. {
    5. setWindowTitle("test Window");
    6. pb1=createLink(tr("& test"),SLOT(open()));
    7. pb1->setVisible(true);
    8. pb1->setGeometry(0,0,40,40);
    9. pb1->setText("test");
    10. QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(open()));
    11. }
    12. void win::open()
    13. {
    14. setWindowTitle("event occured");
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 12th August 2009 at 07:19. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error No such slot QMainWindow::open()

    You forgot Q_OBJECT macro.

  3. #3
    Join Date
    Aug 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: error No such slot QMainWindow::open()

    hi ,

    i placed Q_OBJECT macro after compiling i am getting following error

    main.o: In function `main':
    main.cpp:(.text+0x5e): undefined reference to `vtable for win'
    main.cpp:(.text+0x67): undefined reference to `vtable for win'
    main.cpp:(.text+0xa5): undefined reference to `vtable for win'
    main.cpp:(.text+0xae): undefined reference to `vtable for win'
    win.o: In function `win::win()':
    win.cpp:(.text+0x9c): undefined reference to `vtable for win'
    win.o:win.cpp:(.text+0xa3): more undefined references to `vtable for win' follow
    collect2: ld returned 1 exit status
    make: *** [testWin] Error 1

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: error No such slot QMainWindow::open()

    Quote Originally Posted by kavinsiva View Post
    class win : public : QMainWindow
    Replace this line with this:
    Qt Code:
    1. class win : public QMainWindow
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by kavinsiva View Post
    QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(o pen()));
    Replace this line with this:
    Qt Code:
    1. QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(open()));
    To copy to clipboard, switch view to plain text mode 
    Remove the space in O PEN.

    Quote Originally Posted by kavinsiva View Post
    void win: open()
    Replace this line with
    Qt Code:
    1. void win:: open()
    To copy to clipboard, switch view to plain text mode 
    Notice Scope Resolution Operator.

    And you never allocated memory to QPushButton *pb1; So it will lead to crash.
    Last edited by yogeshgokul; 12th August 2009 at 06:05.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: error No such slot QMainWindow::open()

    Rerun qmake after adding the macro to the class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Differences in calling a Slot
    By Denarius in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2009, 15:32
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44

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.