Results 1 to 19 of 19

Thread: Signals Slots and Class Pointers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Re: Signals Slots and Class Pointers

    Looks like HEADERS in pro are fine.

    As for the code...

    mainwindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "glwidget.h"
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. int m_Angle;
    20. void AngleUpdate(int m_Angle);
    21. private:
    22. Ui::MainWindow *ui;
    23. };
    24.  
    25. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    glwidget.h

    Qt Code:
    1. #ifndef GLWIDGET_H
    2. #define GLWIDGET_H
    3.  
    4. #include <QtOpenGL/QGLWidget>
    5. #include <cmath>
    6. #include "mainwindow.h"
    7. #include <QMessageBox>
    8.  
    9. class GLWidget : public QGLWidget
    10. {
    11. Q_OBJECT
    12. public:
    13. explicit GLWidget(QWidget *parent = 0);
    14.  
    15. int m_Angle;
    16.  
    17.  
    18. void initializeGL();
    19. void paintGL();
    20. void resizeGL(int w, int h);
    21.  
    22. public slots:
    23. void SetAngle(int Angle);
    24.  
    25. };
    26.  
    27. #endif // GLWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->Widget, SLOT(SetAngle(int Angle))); //Widget is just the standard widget which I've promoted to GLWidget in form editor
    10. connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->label, SLOT(setNum(int)));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    To copy to clipboard, switch view to plain text mode 

    glwidget.cpp

    Qt Code:
    1. #include "glwidget.h"
    2.  
    3. GLWidget::GLWidget(QWidget *parent) :
    4. QGLWidget(parent)
    5. {
    6.  
    7. }
    8.  
    9. void GLWidget::SetAngle(int Angle)
    10. {
    11. if (Angle != m_Angle)
    12. {
    13. m_Angle = Angle;
    14. QMessageBox::information(0, "inside slot", "inside slot");
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    P.S. There might be one or two mistakes here or there e.g. m_Angle used instead of Angle or something like that... I'm 99% sure I don't have that mistake in my actual program.
    Last edited by Atomic_Sheep; 19th July 2012 at 07:32.

Similar Threads

  1. Custom QTreeWidgetItem class and signals&slots issue
    By devla in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2012, 01:15
  2. Replies: 3
    Last Post: 6th April 2012, 17:44
  3. Replies: 8
    Last Post: 15th July 2010, 22:42
  4. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 12:14
  5. pointers behaviour in qt and specially signals/slot mechanism
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2008, 20:34

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.