QtCreator UI-designer suddenly fails to add/find slots



  • Hi there,
    I have a middle sized application with a few different ui files. Everything was created inside QtCreator 2.4.1.

    Suddenly I get the following error message when trying to go to or create slots via rightclick->Go to Slot...:
    [quote]The class containing 'Ui::MyWindow' could not be found in
    Z:/my/project/directory/otherfileone.cpp
    Z:/my/project/directory/mywindow.cpp
    Z:/my/project/directory/otherfiletwo.cpp
    Please verify the #include-directives.[/quote]

    the other two .cpp files are the implementation files belonging to other UIs. only the mywindow.cpp belongs to MyWindow. I have verified that mywindow.cpp correctly #includes mywindow.h and ui_mywindow.h. Also, mywindow.h contains the typical namespace Ui { class MyWindow; } section and the class MyWindow contains a public member Ui::MyWindow *ui. I have tried to undo the last few steps I did before this occured, which was creating three actions and adding two private slots. Nothing helped, although it's quite some time back I last tried adding/modifying a slot via the rightclick menu. Of course, the whole project compiles fine, so there aren't any obvious syntax errors which could throw off QtCreators parser. All other UI files work fine.

    What is going on here? How can I repair my project? Gnaaah!



  • Exactly the same problem here, and no ideas how to fix this. Happens with QtCreator 2.5.2 in Linux and Windows.

    I have 9 .ui files and 20 .cpp file. The problem occurs in my MainWindows (QMainWindow), in every other windows "go to slot" works just fine.

    I also checked all #includes, file names and class names: no problems that I could spot - MainWindow has similar #include's, consructors etc. than all other files.

    Any help would be greatly appreciated.



  • Maybe this will give you some hope: After a week or so of creating the slots manually for that specific ui file (by naming the slots appropriately, they get automatically connected to the respective signals), I tried it again via the QtCreator context menu, and it worked again. Still no idea what caused it.



  • Thanks for the tip about naming slots appropriately, that helps! Let's hope my project too will be magically fixed at some point. I tried taking .ui file from old backup where "go to slot" still works, but that didn't help. Also compared .cpp and .h files - no differences that should have anything to do with this. Very strange.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.