Important: Please read the Qt Code of Conduct -

Signals and Slots to connect two windows

  • Hi,
    I am trying to use signals and slots so that when the user double-clicks on a row from my database table, it will open up the second window with the information from the table auto-populated into the fields in that new table:
    However, when creating the signals I can't find the new window, any clue on how to do this via qt designer?

  • Moderators

    You can't. Each window becomes a separate .ui file loaded at runtime into different instances of some classes. There's no way the designer can know how you'll use these files so there's no way to connect anything between them.

    The designer generates a .ui file that translates into C++ code that operates on a QWidget pointer that you give it via parameter of setupUI call. This information is not available when you design your widget. It's only available at runtime, after you already created instances of these widgets. Remember that a connect statememnt takes two pointers - sender and receiver. Designer has access only to the sender in this case.

  • @Chris-Kawa
    Mhmmm a lot of what you said went over my head (beginner), but is it not possible just on Qt Designer or is it also not possible using PyQT5 and hard coding it?

  • Moderators

    @DouglinhasZN I'll try to simplify - each window in the designer becomes a separate object when you run your app. Those objects do not exist when you're designing them so that's why you can't connect them in designer.

    Once your app starts and those objects are created you can connect them. So to naswer your question - yes, you can and should connect them from code.

  • @Chris-Kawa Ah I see thank you
    On a different note, would you happen to know if its possible to create a right clickable menu in each row of a table?
    I want so that when the user right clicks a row, it will display a menu "see in more detail" and when clicked it would show this new window that i will hardcode in.
    But is it possible to add this menu using qt designer? I am attempting by using Action Editor and Signal/slot but no luck yet

  • Moderators

    But is it possible to add this menu using qt designer?

    No. It's the same thing. This menu will be a separate object created at runtime. You don't have access to anything but your window in the designer.

    You could "cheat" in designer by creating a menu in the menu bar and then detaching it in code, but that would be kinda ugly hack.
    I'd suggest to just create that menu and connect it in code.

  • @Chris-Kawa Thank you. Solved!

  • @DouglinhasZN said in Signals and Slots to connect two windows:


    would you mind sharing how you solved it? Thanks.

Log in to reply