QtCreator UI-designer suddenly fails to add/find slots
-
Just stumbled onto this post and I have some further information that might provide some insight.
Just for experimentation, I tested passing "ui" from my mainwindow to another class I created. That worked fine, then for fun, I right clicked on a widget on mainwindow.ui, clicked "Go to slot", chose a signal, and the slot got created in my secondary class (usermanager.cpp). I didn't expect that at all so I removed the passing of ui to usermanager.cpp, and then I began to get the same error posted above when trying to create the slot via right click. I found this post "error creating slot...":http://www.qtcentre.org/threads/33120-Widget-Go-To-Slot-causes-The-class-definition-of-Ui-could-not-be-found , remembered I was still including ui_mainwindow.h in my usermanager.cpp class unecessarily, and when I removed it I was then able to add a slot without error to mainwindow.cpp.
mtnbiker
-
Thanks, now I get it. I too have added '#include "ui_mainwindow.h"' to few other classes, and passed pointer to mainwindow to them. This way I can access mainwindow widgets directly from those other classes. This is not how to design proper applications, I know, but I'm UI-prototyping here.
So apparently these other '#include "ui_mainwindow.h"'s confuse the designer. Have to check if there is some workaround for this (other than fixin my code, that is, hehe).
-
I'm trying to redesign the one Qt project I've done to make it more OO friendly - I did most of the work in mainwindow.cpp - and in order to get around accessing the widgets from other classes I'm doing all my data/model processing in the new classes and leaving all the ui work in mainwindow which leaves me with having to pass data in as parameters.
-
Hi guys, I just met this very same problem. I was refactoring my 3-year old project to c++11. I didn't like my MainWindow class to hold a bare Ui::MainWindow* ui rawpointer deleting it in the destructor. I tried to wrap it into std::unique_ptrUi::MainWindow and cleaned the destructor (for me it seems c++11 encourages us to clean out any ownership-handling responsibilities from destructors). Anyway, when I tried to go to a previously setup slot, I met this problem, too. I changed back the raw-ptr ui, (kept the unique_ptr buddy as well, haha) and it worked again.
-
I'm having this problem as well and no idea how to solve it. Has anybody found a solution yet?
-
I've the same here, I fixed it. For any reason, on moving my window class from a projet to other, it has changed the ui #include from the header file to the .cpp file. So i've deleted the include from the cpp and I put it into my window .h file and it's working again.
I had a problem with the sensitive case of the header files name. Then, just clean all, rebuild all, go to slot, there are a error jet, rebuild all again and it works.
I hope that can help somebody.
(I'm sorry for my bad english)
-
Experienced the same Problem. Unable to right-click(go to slot) in form. The problem was unnecessary includes of my ui file (#include ui_mainwindow.h). Removing all includes of the ui file except the on used in MainWindow aka in MainWindow.h keep the include. After that i was able to use right-click ( go to slot) again. Did not clean Project, just rerun. cheers
-
it seems as if the ui_ include has to be the first one.
-
Hello, I had a similar problem. In my case it was related with the upper and lower case notation of include file names and the corresponding #include derictives. The problem was gone as soon the #include directive and the filenames were written in the same manner. On Windows filenames can be in lower or upper case.There should be no difference when accessing them - but it was. Here my Qt Creator was creating an include file with a filename like mybestclass.h but the include was noted as #include "MyBestClass.h". For some reason it could not create the slots with the "go to slot" functionality. Creating slots manualy was working fine and even jumping to the defintions and declarations with F2. Changing the include and filenam to the same notation solves my problem.
-
@kottalovag I had the same problem and was able to verify that the change from raw pointer to std::unique_ptr broke it. Thanks for the tip, you are a life saver.
In other words, if you have "std::unique_ptr<Ui::MainWindow> ui;" in your mainwindow.h, your project will still build and run, but you won't be able to use "go to slot" from the ui designer. To fix, change it back to "Ui::MainWindow* ui;".