Results 1 to 9 of 9

Thread: Problem with connect

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Problem with connect

    Hello!

    I'm having a problem with connect() function and I wasn't able to find a solution exactly despite numerous related problems have being reported in this forum.

    the problem is: always when I want to make a connect() between a not-ui declared QPushButton and a slot function in a given thing ether the compiler returns error saying "no matching function for call ..." or else its says, when I run the software, that it couldn't find the slot.

    So here is my situation: I'm creating a software that has a MenuBar with one of the options being "Settings". In the settings (a QWidget) there will be a couple of boxes and RadioButton and so forth to choose a couple of options to change my software. In order to make things simpler, I decided to create a specific class for almost all the windows (QWidgets, normally) that will be openend by clicking in the MenuBar.

    The logic is supposed to be as follow:

    1. in the MainWindow (that is connected with the ui and so its the place where the MenuBar click will be called) a pointer to the class with the Setings parameters is created. If the button in MenuBar "Settings" is pressed, a function opens a correspondent method in the windows class.

    2. There, one of the automatic methods that are called is one that creates and connects all the buttons in the Settings window:

    Qt Code:
    1. void MenuWindows::createSettingsBut()
    2. {
    3. //Cria botões de clique
    4. v_butOK = new QPushButton("OK");
    5. v_butCAN = new QPushButton("Cancela");
    6. connect(v_butOK, SIGNAL (released()), this, SLOT (update()));
    7. connect(v_butCAN, SIGNAL( released() ), v_setboxwidget, SLOT( close() ) );
    8.  
    9. //Cria ComboBox (que dá para escolher várias opções) - Qt19
    10. v_combobut1 = new QComboBox(v_setboxwidget);
    11. v_combobut1->addItem("Green");
    12. v_combobut1->addItem("GBR");
    13.  
    14. //Cria botões de escolha (radio) - Qt18
    15. v_radiobut1 = new QRadioButton("Op 1");
    16. ...
    17. }
    To copy to clipboard, switch view to plain text mode 

    one of this buttons is "v_butOK", which is a QPushButton with "OK" on it.

    3. So the guy using the software will set the configurations in the other buttons as he pleases, and once he wants to get out with the new configuration, he press "OK".

    4. In this case, the "OK" QPushButton must be connected with a slot method of the class (class name is "MenuWindows" as seen above) which is named "update()". This method will verify each of the settings parameters to see which changes were made and, based in the analysis, will change the configurations of the software and close the Settings window:

    Qt Code:
    1. void MenuWindows::update()
    2. {
    3. if (v_checkbut1->isChecked())
    4. {
    5. qDebug() << "Graph 1 on.";
    6. }
    7. else
    8. {
    9. qDebug() << "Graph 1 off.";
    10. }
    11. if (v_checkbut2->isChecked())
    12. {
    13. qDebug() << "Graph 2 on.";
    14. }
    15. else
    16. {
    17. qDebug() << "Graph 2 off.";
    18. }
    19. v_setboxwidget->close();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Note: this method is not finished (this is why there is just qDebugs() in it).

    In the case, this update() method was declared as "public slots:" in the header file of the class "MenuWindows".

    But when I run the software as it is above, the compilation says "Object::connect: No such slot QObject::update() in menuwindows.cpp:28". And the slot is there!

    What am I missing?


    Thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with connect

    Show your header file

  3. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with connect

    Qt Code:
    1. #ifndef MENUWINDOWS_H
    2. #define MENUWINDOWS_H
    3.  
    4. //Botões e layouts
    5. #include <QRadioButton>
    6. #include <QCheckBox>
    7. #include <QPushButton>
    8. #include <QVBoxLayout>
    9. #include <QHBoxLayout>
    10. #include <QComboBox>
    11.  
    12. #include <QMainWindow>
    13. #include <QTextEdit>
    14. #include <QString>
    15. #include <QLabel>
    16.  
    17. class MenuWindows : public QObject
    18. {
    19. public:
    20. //Functions
    21. MenuWindows();
    22. void createSettings();
    23. void createSettingsBut();
    24. void showSettings();
    25. void createAbout(QWidget *a);
    26.  
    27. //Variables
    28. //Botões
    29. QRadioButton *v_radiobut1, *v_radiobut2, *v_radiobut3, *v_radiobut4;
    30. QPushButton *v_but1, *v_but2, *v_but3, *v_but4, *v_butOK, *v_butCAN;
    31. QComboBox *v_combobut1, *v_combobut2;
    32. QCheckBox *v_checkbut1, *v_checkbut2, *v_checkbut3, *v_checkbut4, *v_checkbut5, *v_checkbut6;
    33. //Outros
    34. QWidget *v_setboxwidget;
    35. QGridLayout *v_gridlayout;
    36. QHBoxLayout *v_hlayout;
    37. QVBoxLayout *v_vlayout;
    38.  
    39. bool v_ok;
    40.  
    41. public slots:
    42. void update();
    43.  
    44. private:
    45. QString textAbout;
    46. };
    47.  
    48. #endif // MENUWINDOWS_H
    To copy to clipboard, switch view to plain text mode 

    Note: the ": public QObject" was something not present in the original. I put that as part of my work to make the connection works, but, as you may have figured out, it didn't...

  4. #4
    Join Date
    Jul 2011
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4

    Default Re: Problem with connect

    The Q_OBJECT macro is missing in your header file

  5. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with connect

    Quote Originally Posted by nosleduc View Post
    The Q_OBJECT macro is missing in your header file
    Umm, I heard about that earlier. But where am I supposed to put this in the header file? All places where I try, new problems with the compiler arises. For example, if I put it exactly in line 19, the following error appears:

    /home/martin/Documentos/Programas Qt/Servidor 3.4.3/menuwindows.cpp:6: error: undefined reference to `vtable for MenuWindows'
    /home/martin/Documentos/Programas Qt/Servidor 3.4.3/menuwindows.cpp:6: error: undefined reference to `vtable for MenuWindows'

    And how exaclty should I put it?

  6. #6
    Join Date
    Jul 2011
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4

    Default Re: Problem with connect

    Qt Code:
    1. class MenuWindows : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    if you are using qtcreator you can just recompile but if you are using a different IDE you need to use again qmake on your .pro file it depends on the IDE you are using

  7. #7
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with connect

    Well, I'm using Qt creator and I put the macro exactly in the place you (and the Help) indicates, but the problem persists. Here is the complete description of the problem:

    moc_mytask.o moc_myserver.o moc_myclient.o -L/home/martin/QtSDK/Desktop/Qt/473/gcc/lib -L/usr/local/lib -lqwt-qt4 -lQtSvg -lQtGui -lQtNetwork -lQtCore -lpthread
    menuwindows.o: In function `MenuWindows':
    make: Saindo do diretório `/home/martin/Documentos/Programas Qt/Servidor 3.4.3'
    /home/martin/Documentos/Programas Qt/Servidor 3.4.3/menuwindows.cpp:6: undefined reference to `vtable for MenuWindows'
    /home/martin/Documentos/Programas Qt/Servidor 3.4.3/menuwindows.cpp:6: undefined reference to `vtable for MenuWindows'
    collect2: ld returned 1 exit status
    make: ** [Servidor] Erro 1
    The process "/usr/bin/make" exited with code 2.
    Error while building project Servidor (target: )
    When executing build step 'Make'

    It points to the cpp file.

  8. #8
    Join Date
    Jul 2011
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4

    Default Re: Problem with connect

    In the build menu
    1) Clean All
    2) Run qmake
    3) Rebuild all

  9. #9
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with connect

    Oh! Finally!

    Thanks!

Similar Threads

  1. Problem with connect
    By eekhoorn12 in forum Newbie
    Replies: 3
    Last Post: 21st December 2010, 21:48
  2. connect() problem
    By harmodrew in forum Newbie
    Replies: 14
    Last Post: 5th August 2010, 18:45
  3. Connect Problem
    By nrabara in forum Newbie
    Replies: 3
    Last Post: 4th May 2009, 13:19
  4. connect problem
    By liengen in forum Newbie
    Replies: 2
    Last Post: 22nd October 2008, 17:21
  5. Problem with connect()
    By mrnor3 in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2008, 15:05

Tags for this Thread

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.