Results 1 to 20 of 20

Thread: custom slots / generated ui

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Re: custom slots / generated ui

    Using the Designer, I was not really sure what needs to be done where.
    So when I try to add the "public slots:" in "generat0rX.h", I get a linker error that states something around
    Qt Code:
    1. "symbol not found in ui_generat0rX.h"
    To copy to clipboard, switch view to plain text mode 
    (I am not at my workstation, can post the exact linker error later). When I remove the "public slots:" statements, the code compiles again.

    I have created the two additional slots also in Designer (as part of generat0rXClass) by right-clicking on generat0rXClass and editing "Signals/Slots".

    On the "isn't valid c++": What is wrong with it? (btw: I copy/pasted it from a Nokia Qt tutorial )
    Last edited by mboeni; 13th October 2010 at 10:19.

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

    Default Re: custom slots / generated ui

    Once you have added slots to a header file, you must invoke the MOC to generate the appropriate dependancies. This is typically done by updating the project (In QtCreator I think is called "run qmake" or similar).

    Please post a link to the Nokia Qt tutorial.

  3. #3
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Re: custom slots / generated ui

    I changed generat0rx.h to this:
    Qt Code:
    1. #ifndef GENERAT0RX_H
    2. #define GENERAT0RX_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_generat0rx.h"
    6.  
    7. class generat0rX : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. generat0rX(QWidget *parent = 0, Qt::WFlags flags = 0);
    13. ~generat0rX();
    14.  
    15. //void exit_slot();
    16. //void addScene2D_slot();
    17.  
    18. public slots:
    19. void exit_slot(void);
    20. void addScene2D_slot(void);
    21.  
    22.  
    23. private:
    24. Ui::generat0rXClass ui;
    25.  
    26. };
    27.  
    28. #endif // GENERAT0RX_H
    To copy to clipboard, switch view to plain text mode 

    which, when compiling gives me this output:
    Qt Code:
    1. 1>------ Build started: Project: generat0rX, Configuration: Debug Win32 ------
    2. 1> Moc'ing include\generat0rx.h...
    3. 1> moc_generat0rx.cpp
    4. 1> generat0rx.cpp
    5. 1> main.cpp
    6. 1> Generating Code...
    7. 1>moc_generat0rx.obj : error LNK2019: unresolved external symbol "public: void __thiscall generat0rX::addScene2D_slot(void)" (?addScene2D_slot@generat0rX@@QAEXXZ) referenced in function "public: virtual int __thiscall generat0rX::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@generat0rX@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    8. 1>moc_generat0rx.obj : error LNK2019: unresolved external symbol "public: void __thiscall generat0rX::exit_slot(void)" (?exit_slot@generat0rX@@QAEXXZ) referenced in function "public: virtual int __thiscall generat0rX::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@generat0rX@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    9. 1>E:\workspace\QTProjects\generat0rX\\generat0rX.exe : fatal error LNK1120: 2 unresolved externals
    10. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    To copy to clipboard, switch view to plain text mode 

    I pasted the full output so you see what the compiler (MSVS / QT Add-In in my case) does. It says that it does moc things as far as I can tell.

    Here is the link to the sample: http://doc.trolltech.com/4.7/qmessagebox.html

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: custom slots / generated ui

    Did have any CPP file with methods void generat0rX::exit_slot(void) and void generat0rX::addScene2D_slot(void) definitions ?

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

    Default Re: custom slots / generated ui

    By "not valid C++", I mean this:

    Qt Code:
    1. void exit_slot()
    2. {
    3. QMessageBox msgBox;
    4. msgBox.setText("SLOT: exit_slot triggered");
    5. msgBox.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    to this:

    Qt Code:
    1. void generat0rX::exit_slot()
    2. {
    3. QMessageBox msgBox;
    4. msgBox.setText("SLOT: exit_slot triggered");
    5. msgBox.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Re: custom slots / generated ui

    @Lesiok:

    Yes, the methods are defined here:
    Qt Code:
    1. #include "generat0rx.h"
    2. #include "qmessagebox.h"
    3.  
    4.  
    5. generat0rX::generat0rX(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
    6. {
    7. ui.setupUi(this);
    8.  
    9. }
    10.  
    11. generat0rX::~generat0rX()
    12. {
    13.  
    14. }
    15.  
    16.  
    17. void generat0rX::exit_slot()
    18. {
    19. QMessageBox msgBox;
    20. msgBox.setText("SLOT: exit_slot triggered");
    21. msgBox.exec();
    22.  
    23. //qApp->quit();
    24. //qApp->exit();
    25. }
    26.  
    27. void generat0rX::addScene2D_slot()
    28. {
    29. QMessageBox msgBox;
    30. msgBox.setText("SLOT: addScene2D triggered");
    31. msgBox.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

    Any idea whats wrong?

Similar Threads

  1. Accessing generated pixmaps in html / Custom tooltips
    By Pieter from Belgium in forum Qt Programming
    Replies: 9
    Last Post: 1st August 2009, 16:24
  2. Creating custom slots
    By harb37 in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2008, 19:10
  3. Replies: 12
    Last Post: 23rd June 2008, 09:05
  4. Replies: 2
    Last Post: 12th July 2007, 10:55
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.