0

So, I've been working on my GUI and it's gotten pretty large, so I decided to split it into multiple widgets that communicate with the main window (probably something that I should have done from the beginning). I've partitioned part of my GUI into a separate widget, but I'm having trouble setting up signals and slots between the main window and the new widget, and I was hoping you could help me figure out what I'm doing wrong.

The main window is called robotmainwindow and the widget is called robotTabWidget. In robotmainwindow.h, I forward declared robotTabWidget as such:

robotTabWidget* robotttabwidget;

Then, in robotmainwindow.cpp, I initialized the class:

robottabwidget = new robotTabWidget();

I have function called create connections in robotmainwindow, in which I try to connect a signal from robotTabWidget to a slot in robotmainwindow:

void robotmainwindow::createConnections()
{
connect(robottabwidget, &robotTabWidget::sigSendCartCommand, this, &robotmainwindow::slotOnSendCartCommand);
}

The signal sigSendCartCommand is defined in robottabwidget.h:

void sigSendCartCommand(double);

And emitted in robotTabWidget::on_SendCartCommand_clicked():

emit sigSendCartCommand(CartCommand);

But when I attempt to compile, I get a "no matching function for call to" for the connect function, and "robotTabWidget::sigSendCartCommand(double) is protected". Why is the signal protected? I thought you could emit a signal from anywhere. And why am I getting a "no matching function" error?

This has been giving me a lot of trouble for the last few days and I haven't been able to figure it out. I'd greatly appreciate your help!

edit: I've changed things around, and fixed a few things but I'm still getting errors. The connect function now looks like:

QObject::connect(myrobotTabWidget, robotTabWidget::sigTest(test), this, &robotmainwindow::slotOnSendCartCommand);

The error I'm now getting is "cannot call member function without object":

../RobotInterface2/robotmainwindow.cpp:102:68: error: cannot call member function 'void robotTabWidget::sigTest(QString)' without object
 QObject::connect(myrobotTabWidget, robotTabWidget::sigTest(test), this, &robotmainwindow::slotOnSendCartCommand);

And the arrow is pointing at robotTabWidget::sigTest(QString). I'm not sure what to do about this. Any ideas?

  • Which Qt version, 4.* or 5.*? Also, post the complete error message, as output by the compiler. You need to be exact with computers! I think a little more code wouldn't hurt either. Note: you forward declare a *class*, not an object. Also, what you actually do is declare a pointer to an object, which is initially invalid. And then, you do not "initialize the class", but create an instance of that class. I suggest you brush up on C++ a little! – iksemyonov Feb 02 '16 at 01:31
  • Make sure that `robotmainwindow` inherits from QObject, and that you have put the `Q_OBJECT` macro in the class declaration! That's a common mistake to forget to do so. – iksemyonov Feb 02 '16 at 01:36
  • You can't emit signals outside the class where they are defined in the Qt 4.x. In Qt 5.x it's possible. – Tomas Feb 02 '16 at 10:15
  • Thank you for the terminology corrections, I will keep those in mind for future reference. I do have the 'Q_OBJECT' macro in the class direction, so that does not seem to be the issue. I'm also using Qt 5.x, so it is possible to emit signals from another class (although the signal is being emitted in robotTabWidget, not robotmainwindow, so I don't think it's being emitted from outside its class). I've changed things around and the new connect function looks like: 'QObject::connect(myrobotTabWidget, robotTabWidget::sigTest(test), this, &robotmainwindow::slotOnSendCartCommand);' – Shaheer Khan Feb 02 '16 at 20:20

0 Answers0