Results 1 to 2 of 2

Thread: slot problem

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android
    Thanks
    40

    Default slot problem

    Hello,

    I promoted a widget to a custom widget (scalableWidget)...But when i run the application i get a slot connection problem error like:

    Object::connect: No such slot QWidget::setScaleVal(int)
    Object::connect: (sender name: 'horizontalSlider')
    Object::connect: (receiver name: 'widget')

    I couldn't find anything wrong...What may be the problem...?

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
    4. : QMainWindow(parent, flags)
    5. {
    6. ui.setupUi(this);
    7. QObject::connect(ui.horizontalSlider, SIGNAL(valueChanged(int)), ui.widget, SLOT(setScaleVal(int)));
    8.  
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    my custom widget:

    Qt Code:
    1. #ifndef SCALABLEWIDGET_H
    2. #define SCALABLEWIDGET_H
    3. #include <QWidget>
    4. #include <QPainter>
    5.  
    6. class scalableWidget : public QWidget
    7. {
    8.  
    9. public:
    10. scalableWidget(QWidget * parent = 0, Qt::WindowFlags f = 0);
    11. qreal scaleFactor;
    12.  
    13. protected:
    14. void paintEvent(QPaintEvent *event);
    15.  
    16. public slots:
    17. void setScaleVal(int);
    18.  
    19. };
    20.  
    21. #endif // SCALABLEWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "scalablewidget.h"
    2.  
    3. scalableWidget::scalableWidget(QWidget * parent, Qt::WindowFlags f)
    4. :QWidget( parent, f )
    5. {
    6. }
    7.  
    8. void scalableWidget::paintEvent(QPaintEvent *event)
    9. {
    10. QPainter painter(this);
    11. painter.scale(scaleFactor,scaleFactor);
    12.  
    13. }
    14.  
    15. void scalableWidget::setScaleVal(int comingValue)
    16. {
    17. scaleFactor=(qreal)comingValue;
    18. }
    To copy to clipboard, switch view to plain text mode 

    generated file :

    Qt Code:
    1. #ifndef UI_MAINWINDOW_H
    2. #define UI_MAINWINDOW_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QMainWindow>
    9. #include <QtGui/QMenuBar>
    10. #include <QtGui/QPushButton>
    11. #include <QtGui/QSlider>
    12. #include <QtGui/QStatusBar>
    13. #include <QtGui/QToolBar>
    14. #include <QtGui/QWidget>
    15. #include "scalablewidget.h"
    16.  
    17. QT_BEGIN_NAMESPACE
    18.  
    19. class Ui_MainWindowClass
    20. {
    21. public:
    22. QWidget *centralWidget;
    23. scalableWidget *widget;
    24. QPushButton *pushButton;
    25. QPushButton *pushButton_2;
    26. QSlider *horizontalSlider;
    27. QMenuBar *menuBar;
    28. QToolBar *mainToolBar;
    29. QStatusBar *statusBar;
    30.  
    31. void setupUi(QMainWindow *MainWindowClass)
    32. {
    33. if (MainWindowClass->objectName().isEmpty())
    34. MainWindowClass->setObjectName(QString::fromUtf8("MainWindowClass"));
    35. MainWindowClass->resize(600, 400);
    36. centralWidget = new QWidget(MainWindowClass);
    37. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    38. widget = new scalableWidget(centralWidget);
    39. widget->setObjectName(QString::fromUtf8("widget"));
    40. widget->setGeometry(QRect(220, 30, 171, 131));
    41. pushButton = new QPushButton(widget);
    42. pushButton->setObjectName(QString::fromUtf8("pushButton"));
    43. pushButton->setGeometry(QRect(40, 30, 80, 25));
    44. pushButton_2 = new QPushButton(widget);
    45. pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    46. pushButton_2->setGeometry(QRect(70, 80, 80, 25));
    47. horizontalSlider = new QSlider(centralWidget);
    48. horizontalSlider->setObjectName(QString::fromUtf8("horizontalSlider"));
    49. horizontalSlider->setGeometry(QRect(70, 210, 160, 16));
    50. horizontalSlider->setOrientation(Qt::Horizontal);
    51. MainWindowClass->setCentralWidget(centralWidget);
    52. menuBar = new QMenuBar(MainWindowClass);
    53. menuBar->setObjectName(QString::fromUtf8("menuBar"));
    54. menuBar->setGeometry(QRect(0, 0, 600, 23));
    55. MainWindowClass->setMenuBar(menuBar);
    56. mainToolBar = new QToolBar(MainWindowClass);
    57. mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
    58. MainWindowClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
    59. statusBar = new QStatusBar(MainWindowClass);
    60. statusBar->setObjectName(QString::fromUtf8("statusBar"));
    61. MainWindowClass->setStatusBar(statusBar);
    62.  
    63. retranslateUi(MainWindowClass);
    64.  
    65. QMetaObject::connectSlotsByName(MainWindowClass);
    66. } // setupUi
    67.  
    68. void retranslateUi(QMainWindow *MainWindowClass)
    69. {
    70. MainWindowClass->setWindowTitle(QApplication::translate("MainWindowClass", "MainWindow", 0, QApplication::UnicodeUTF8));
    71. pushButton->setText(QApplication::translate("MainWindowClass", "PushButton", 0, QApplication::UnicodeUTF8));
    72. pushButton_2->setText(QApplication::translate("MainWindowClass", "PushButton", 0, QApplication::UnicodeUTF8));
    73. Q_UNUSED(MainWindowClass);
    74. } // retranslateUi
    75.  
    76. };
    77.  
    78. namespace Ui {
    79. class MainWindowClass: public Ui_MainWindowClass {};
    80. } // namespace Ui
    81.  
    82. QT_END_NAMESPACE
    83.  
    84. #endif // UI_MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    70
    Thanked 59 Times in 57 Posts

    Default Re: slot problem

    Hi,

    It seems that you forget the Q_OBJECT macro:

    Qt Code:
    1. class scalableWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  2. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 15:44
  3. problem with slot
    By as001622 in forum Qt Programming
    Replies: 4
    Last Post: 24th May 2008, 09:02
  4. Problem with slot
    By beerkg in forum Qt Programming
    Replies: 29
    Last Post: 3rd April 2007, 20:54

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.