Nope, looks I'm too stupid to figure this one out, after spending a few hours on this, I still can't get it to work.
I've got the two classes (mainwindow and glwidget)... in the mainwindow class constructor I've connected:
Qt Code:
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->widget, SLOT(...);To copy to clipboard, switch view to plain text mode
However as the ... indicates... no slots from my glwidget class pop up.
The glwidget and mainwindow are two seperate classes with their own .h and .cpp files and I've definitely added the includes but still no luck.
I added a label to my ui and connected that to the horizontalslider and the label shows the values no problems and also pops up with "setNum(int)" when I'm typing up the connect command...
Qt Code:
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->label, SLOT(setNum(int)));To copy to clipboard, switch view to plain text mode
I've also written the code for my slot in my glwidget.cpp file:
Qt Code:
void GLWidget::SetValue(int Value) { if (Value != m_Value) { m_Value = Value; } }To copy to clipboard, switch view to plain text mode
But still no luck.
Last edited by Atomic_Sheep; 18th July 2012 at 11:36.
The fact that Creator does not recognize your slot, doesn't mean you can't use it. Just type in the slot signature manually. And make sure you really declared the function to be a slot.
I was wondering whether this might be the case so I tried what you suggested but the implementation of my receiving objects slot doesn't appear to be registering because my opengl's object rotation doesn't appear to be happening. I put a messagebox inside my slot implementation and it doesn't pop up as I move the slider about... the value in the label changes though.
We'd have to see your actual code as currently with those little pieces you posted it is hard to tell anything. In general you need your method to be declared as a slot and you need to be passing a pointer to an instance of that class to the connect() statement to be able to connect to the slot.
Also look at the debug output of your program for warnings of the type:
indicating that the SetValue() function is not declared as a slot. The glwidget.h file should look like:Qt Code:
To copy to clipboard, switch view to plain text mode
and be included in the PRO file HEADERS variable.Qt Code:
... class GLWidget: public ... { Q_OBJECT public: GLWidget(...); ... public slots: // <<<< this void SetValue(int value); ... }; ...To copy to clipboard, switch view to plain text mode
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
Looks like HEADERS in pro are fine.
As for the code...
mainwindow.h
Qt Code:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "glwidget.h" namespace Ui { class MainWindow; } { Q_OBJECT public: ~MainWindow(); int m_Angle; void AngleUpdate(int m_Angle); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_HTo copy to clipboard, switch view to plain text mode
glwidget.h
Qt Code:
#ifndef GLWIDGET_H #define GLWIDGET_H #include <QtOpenGL/QGLWidget> #include <cmath> #include "mainwindow.h" #include <QMessageBox> { Q_OBJECT public: int m_Angle; void initializeGL(); void paintGL(); void resizeGL(int w, int h); public slots: void SetAngle(int Angle); }; #endif // GLWIDGET_HTo copy to clipboard, switch view to plain text mode
mainwindow.cpp
Qt Code:
#include "mainwindow.h" #include "ui_mainwindow.h" ui(new Ui::MainWindow) { ui->setupUi(this); 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 connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->label, SLOT(setNum(int))); } MainWindow::~MainWindow() { delete ui; }To copy to clipboard, switch view to plain text mode
glwidget.cpp
Qt Code:
#include "glwidget.h" { } void GLWidget::SetAngle(int Angle) { if (Angle != m_Angle) { m_Angle = Angle; } }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 06:32.
In the last few posts the slot has been referred to as SetNum(), SetValue(), and now SetAngle(). I asked you to check for run time error messages like:
Line 9 of mainwindow.cpp is probably generating one because the slot signature is incorrect. You do not include the argument names in the signal or slot signatures.Qt Code:
To copy to clipboard, switch view to plain text mode
Forgot to say that yes I did check for those errors, I didn't see any, but I just realised that run-time errors are under "Application Output" and yes it's spitting out the "no such slot" error. i.e. :
Object::connect: No such slot GLWidget::SetAngle(int Angle) in ...\MainWindow.cpp:9
Object::connect: (sender name: 'horizontalSlider')
Object::connect: (receiver name: 'Widget')
...exited with code 0
I used different names for my slots previously because I was simply typing the code up as I was writing up the message. In the latest iteration it was copy paste with some minor editing, but the latest code that I provided should have all the naming issues sorted out.
Still unable to get my signals and slots to work.
my .cpp files are :main.cpp, button.cpp, mainWindow.cpp and mainWindowWidget.cpp.
mainWindowWidget.cpp has the following signal:
Qt Code:
{ if(event->button() == Qt::LeftButton) //left mouse button - need to check this. { cMousePositionAtClick = event->pos(); emit MouseClickLocation(cMousePositionAtClick); //QMessageBox::information(this, "Mouse Click Detected", "Mouse Click Detected"); } }To copy to clipboard, switch view to plain text mode
I have a slot in my button.h and its implementation.
here's the code in main.cpp:
Qt Code:
mainWindow w; Button button1(0,0,50,50); w.show();To copy to clipboard, switch view to plain text mode
However when I compile it I get the following errors:
main.cpp:11: error: cannot convert 'mainWindow' to 'SOCKET' for argument '1' to 'int connect(SOCKET, const sockaddr*, int)'
Last edited by Atomic_Sheep; 3rd September 2012 at 05:40.
Two basic C++, not Qt, problems:
The error message tells you that the compiler has found only function 'int connect(SOCKET, const sockaddr*, int)' when trying to compile line 11 (I assume line 3 of your posted snippet). The arguments you have given cannot be coerced into the arguments required by that function so it fails. You want QObject::connect() and you cannot access that as an unqualified name outside of the implementation of a QObject sub-class. Use the static QObject::connect() function.
QObject::connect() requires a pointer to an object, i.e. &w and &button1, not the actual objects as you are current trying to do.
Deleted... figured it out.
Last edited by Atomic_Sheep; 4th September 2012 at 07:29.
Bookmarks