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

    Ok, I tried it the manual way also: I removed the two custom slots and the connection in designer and did it in code. My class now looks like this:

    generat0rx.h
    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, private Ui::generat0rXClass
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. generat0rX(QWidget *parent = 0, Qt::WFlags flags = 0);
    13. ~generat0rX();
    14.  
    15. public slots:
    16. void exit_slot(void);
    17. void addScene2D_slot(void);
    18.  
    19. private:
    20. Ui::generat0rXClass ui;
    21. };
    22.  
    23. #endif // GENERAT0RX_H
    To copy to clipboard, switch view to plain text mode 

    and generat0rx.cpp
    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. QObject::connect(actionExit, SIGNAL(activated()), this, SLOT(exit_slot()));
    9. QObject::connect(actionNew_2D_Scene, SIGNAL(activated()), this, SLOT(addScene2D_slot()));
    10. }
    11.  
    12. generat0rX::~generat0rX()
    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 

    Now the above error is gone but I get a runtime exception:
    Qt Code:
    1. > QtCored4.dll!QObject::connect(const QObject * sender=0x00690000, const char * signal=0x00c5d294, const QObject * receiver=0x0026f5c0, const char * method=0x00c5d270, Qt::ConnectionType type=AutoConnection) Line 2483 + 0x8 bytes C++
    2. generat0rX.exe!generat0rX::generat0rX(QWidget * parent=0x00000000, QFlags<enum Qt::WindowType> flags={...}) Line 8 + 0x31 bytes C++
    3. generat0rX.exe!main(int argc=1, char * * argv=0x0069f9f0) Line 24 + 0x1d bytes C++
    4. generat0rX.exe!WinMain(HINSTANCE__ * instance=0x00980000, HINSTANCE__ * prevInstance=0x00000000, char * __formal=0x00072b9a, int cmdShow=1) Line 131 + 0x12 bytes C++
    5. generat0rX.exe!__tmainCRTStartup() Line 547 + 0x2c bytes C
    6. generat0rX.exe!WinMainCRTStartup() Line 371 C
    To copy to clipboard, switch view to plain text mode 

    and the debugger points to this line in "qobject.cpp":
    Qt Code:
    1. const QMetaObject *smeta = sender->metaObject();
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 18 Times in 18 Posts

    Default Re: custom slots / generated ui

    Your toolbar probably contains one or more QToolButtons. When such button is clicked, the clicked signal for that button is emitted. To react to the signal, you must have in the constructor of your class something like this:
    Qt Code:
    1. connect(myButton, SIGNAL(clicked()), this, SLOT(mySlot()));
    To copy to clipboard, switch view to plain text mode 
    Then every time the button is clicked, the code in function mySlot() is executed.

    In your GeneratorClass.h you have something like:
    Qt Code:
    1. private slots:
    2. void mySlot();
    To copy to clipboard, switch view to plain text mode 

    And.. please read the Qt-docs about signals and slots. It really helps...

  3. #3
    Join Date
    Oct 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: custom slots / generated ui

    Try the signal "triggered()" of your actions instead of "activated()":

    #
    QObject::connect(actionExit, SIGNAL(triggered()), this, SLOT(exit_slot()));
    #
    QObject::connect(actionNew_2D_Scene, SIGNAL(triggered()), this, SLOT(addScene2D_slot()));

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

    Default Re: custom slots / generated ui

    Hi all

    First of all, thanks for the input! Alas, none of it worked.

    I tried something very simple and get exceptions too. So I assume the problem is rooted deeper. I have added a simple widget manipulation to generat0rx.cpp:
    Qt Code:
    1. #include "generat0rx.h"
    2. #include "qmessagebox.h"
    3. #include <QxtLogger>
    4. #include <QxtBasicFileLoggerEngine>
    5.  
    6. generat0rX::generat0rX(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags)
    7. {
    8. ui.setupUi(this);
    9. //QObject::connect(actionExit, SIGNAL(activated()), this, SLOT(exit_slot()));
    10. //QObject::connect(actionNew_2D_Scene, SIGNAL(activated()), this, SLOT(addScene2D_slot()));
    11.  
    12. //Start logging
    13. qxtLog->addLoggerEngine("FileLogger", new QxtBasicFileLoggerEngine("log/g0x.log"));
    14. qxtLog->info("Huhu INFO log entry!");
    15.  
    16.  
    17. outputTabTextEdit->append("TEST");
    18. }
    19.  
    20. generat0rX::~generat0rX()
    21. {
    22.  
    23. }
    24.  
    25. void generat0rX::exit_slot()
    26. {
    27. QMessageBox msgBox;
    28. msgBox.setText("SLOT: exit_slot triggered");
    29. msgBox.exec();
    30.  
    31. //qApp->quit();
    32. //qApp->exit();
    33. }
    34.  
    35. void generat0rX::addScene2D_slot()
    36. {
    37. QMessageBox msgBox;
    38. msgBox.setText("SLOT: addScene2D triggered");
    39. msgBox.exec();
    40. }
    To copy to clipboard, switch view to plain text mode 

    This line was added in the constructor:
    Qt Code:
    1. outputTabTextEdit->append("TEST");
    To copy to clipboard, switch view to plain text mode 

    and even THIS raises an exception. There must be something fundamentally wrong with the way I call ui elements...(I am using multiple inheritance btw). Just to make sure you get the full picture, here is generat0rx.h as well:

    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, private Ui::generat0rXClass
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. generat0rX(QWidget *parent = 0, Qt::WFlags flags = 0);
    13. ~generat0rX();
    14.  
    15. public slots:
    16. void exit_slot(void);
    17. void addScene2D_slot(void);
    18.  
    19. private:
    20. Ui::generat0rXClass ui;
    21. };
    22. #endif // GENERAT0RX_H
    To copy to clipboard, switch view to plain text mode 

    This is getting really frustrating :s

    Here is the call stack:
    Qt Code:
    1. > QtGuid4.dll!QTextEdit::append(const QString & text="TEST") Line 2617 + 0x7 bytes C++
    2. generat0rX.exe!generat0rX::generat0rX(QWidget * parent=0x00000000, QFlags<enum Qt::WindowType> flags={...}) Line 17 + 0x2e bytes C++
    3. generat0rX.exe!main(int argc=1, char * * argv=0x0079fab0) Line 17 + 0x1d bytes C++
    4. generat0rX.exe!WinMain(HINSTANCE__ * instance=0x01040000, HINSTANCE__ * prevInstance=0x00000000, char * __formal=0x000a2b9a, int cmdShow=1) Line 131 + 0x12 bytes C++
    5. generat0rX.exe!__tmainCRTStartup() Line 547 + 0x2c bytes C
    6. generat0rX.exe!WinMainCRTStartup() Line 371 C
    7. kernel32.dll!76e31194()
    8. [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
    9. ntdll.dll!775eb495()
    10. ntdll.dll!775eb468()
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: custom slots / generated ui

    You are mixing the different approaches of using ui files: See "Using a Designer UI File in Your Application" at the docs.
    Use
    Qt Code:
    1. setupUi(this);
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. ui.setupUi(this);
    To copy to clipboard, switch view to plain text mode 
    and rerun qmake.

  6. The following user says thank you to Lykurg for this useful post:

    mboeni (18th October 2010)

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

    Default Re: custom slots / generated ui

    Hi Lykurg

    I have read the article you mentioned, but missed the part about setupUI. Changing that as you proposed has solved my main issues. Thanks!

    Cheers,
    Michael

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

    Default Re: custom slots / generated ui

    For all other newbies out there, I have put together a little tutorial on how to master the first few steps with Qt4 and MS Visual Studio using the Add-In.

    You find the tutorial here: Beginners Tutorial Qt 4.7 with Visual Studio and the Qt Add-In

    Please comment or PM me in the blog if you find any errors.

    All the best,
    Michael

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, 15:24
  2. Creating custom slots
    By harb37 in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2008, 18:10
  3. Replies: 12
    Last Post: 23rd June 2008, 08:05
  4. Replies: 2
    Last Post: 12th July 2007, 09:55
  5. Replies: 16
    Last Post: 7th March 2006, 15: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.