Results 1 to 6 of 6

Thread: Slot not working

  1. #1
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    1

    Default Slot not working

    Hello, I am writing a qt program in VS 6.0.

    I have a window with a button on it. When the button is pressed it will create a file dialog box. I have placed the window and wrote the code to hopefully do this. I have the class that contains the slot.

    Qt Code:
    1. class Panel : public QWidget
    2. {
    3.  
    4. public:
    5. Panel(QWidget *parent = 0, QObject *app = 0);
    6. ...methods
    7.  
    8. private slots:
    9. void openFieldDialog();
    10.  
    11. private:
    12. ...variables
    13. };
    To copy to clipboard, switch view to plain text mode 

    Here is the code for the slot:

    Qt Code:
    1. void Panel::openFieldDialog()
    2. {
    3. ...code
    4. }
    To copy to clipboard, switch view to plain text mode 

    Here is the line where I use the connect for it:

    Qt Code:
    1. QPushButton *loadFile = new QPushButton("Load File", mainFrame);
    2. //this = Panel
    3. QObject::connect(loadFile, SIGNAL(clicked()), this, SLOT(Panel::openFieldDialog()));
    To copy to clipboard, switch view to plain text mode 

    I then compile and build in VS 6.0 and run the program. Nothing happens when I click on the button and on the console window that appears this is seen (it is present before I click):
    Object::connect: No such slot QWidget::Panel:penFieldDialog()

    I have tried numerous other things, such as openFieldDialog() instead of Panel::..., etc.

    Any ideas?

    Thank you!!

    PS:

    Also is there a way to get qmake to work with the makefile for VS 6.0? I'd rather to have all of my compiling done with 1 thing.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slot not working

    Whenever you have either signal or slot used in a class you need to add the Q_OBJECT macro.

    Your class should be something like

    Qt Code:
    1. class Panel : public QWidget
    2. {
    3.  
    4. Q_OBJECT
    5.  
    6. public:
    7. Panel(QWidget *parent = 0, QObject *app = 0);
    8. ...methods
    9. private slots:
    10. void openFieldDialog();
    11. private:
    12. ...variables
    13. };
    To copy to clipboard, switch view to plain text mode 

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

    dayrinni (2nd September 2006)

  4. #3
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    1

    Default Re: Slot not working

    Hmm, I cannot compile if Q_OBJECT is in present in VS 6.0.

    I haven't figured out how to make it work with VS 6.0. Do you know how I can incorprate the qmake into VS ?

  5. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slot not working

    This might help

  6. #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: Slot not working

    You might want to remove the namespace ("Panel::") from the slot name. I'm not sure if the slot normaliser is able to accept that as a proper slot name. You still have to provide Q_OBJECT of course...

  7. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Slot not working

    If you are using VS 6.0

    Do you have the Qt plugins installed.

    If so
    Open the header file and click on the moc tool button, This will add a moc_filename.cpp to the project.
    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. removeAll not working
    By cristianbdg in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2007, 14:23
  2. Problem with slot
    By beerkg in forum Qt Programming
    Replies: 29
    Last Post: 3rd April 2007, 19:54
  3. Replies: 1
    Last Post: 11th June 2006, 22:25
  4. SLOT and QPushButton
    By mickey in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2006, 06:46
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.