Slot seemingly not recognized in Qt app [duplicate]

早过忘川 提交于 2019-12-02 13:27:31

Possibly you have forgotten a Q_OBJECT macro in your Window class?

class Window : public QWidget
{
Q_OBJECT
public:
    Window()
...

Well I was having this problem too and could find no help on-line. I found out that I was forgetting to delete the moc_* files before recompiling and it was using the old moc files to create the executable file. This caused it to not know about any new slots I had coded. I would check that if all the rest of these suggestions failed.

Sometimes the simplest solution is the best solution...

What is runBtn, and how is it created? If it's created as part of a ui file, are you calling setupUi()? How is your window class being created? You seem to have omitted some code (// ...) which may be where the error is.

The best advice I can give to to try and reduce your problem to a very small compilable example. This helps for two reasons:

  1. It helps you diagnose the problem, since there'll be less code to look at.
  2. If you still need our help, it'll help us since we will have a complete codebase we can download, compile and debug. Often the problem is not where you think it is.

Hope this helps.

Looks like runBtn is not instantiated at the time connect is called -- as implied by one of the other answers.

Use breakpoints to check where the crash is happening.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!