Purple Error in Widget Project
-
The arrows are all pointing at the MainWindow (or Clock_Application), so this is what made me wonder whether you can only declare slots in the MainWindow (or Clock_Application) class.
-
There's nothing magical about MainWindow or Clock_Application or anything like that. There's just a connection being made somewhere (looks like in your .ui file) which is still expecting the timer_Start() slot (etc.) to be in the old location. Just moving the slot definition isn't enough to make the .ui file look point to the right place.
What are you doing in the clock_application.ui file which calls timer_Start()? What triggers timer_Start() to be called?
-
timer_Start() is triggered by a click of a button in the widget application. The button is a simple QPushButton.
-
Where is the connection made?
-
When you say "connection" do you refer to my connect() function? If so, here it is:
@
void Stopwatch::timer_Start()
{
stopwatchTimer = new QTimer();
connect(stopwatchTimer, SIGNAL(timeout()), this, SLOT(timer_changeTime()));
stopwatchTimer->start(1000);
}
@ -
No. What makes the button call timer_Start(). How do you tell it to do this?
-
I use that one menu in Qt Designer that allows you to draw blue/red arrows. I then create a new slot, and call it "timer_Start()", and I believe, this automatically connects the clicked() signal and the timer_Start() slot.
-
The arrows need to point to Stopwatch, not Clock_Application, if the slots are defined in Stopwatch.
Behind the scenes, those arrows translate to a "connect()" call in the ui_clock_application.h file.
-
How do I get it to "point" to Stopwatch? Stopwatch is just a class. It does not really refer to any widget.
-
Ah. Good point. In that case, I'd say that there shouldn't be any arrows anywhere, and that you should make the connection in code.
Edit to add:
Alternately, you could keep "proxy" slots in your Clock_Application widget, and from within those slots just call the slots in Stopwatch.
That is to say:
@
class Clock_Application ...
{
Q_OBJECT
...
public slots:
void timer_Start() { m_stopwatch->timer_Start(); } // just "pass through" to your Stopwatch class. (Remember that slots are just plain old methods too, and can be directly called like any other method.)
...
private:
Stopwatch *m_stopwatch;
};
@ -
Hmm.. now I am receiving a strange error:
multiple definition of
ui
first defined here
collect2: Id returned 1 exit statusThe lines in where the errors occur do not seem to be in my project, but in other files.. possibly library files? It's also strange, because I have defined my own
ui
just previously, and am wondering what is causing it now.