Important: Please read the Qt Code of Conduct -

CustomContextMenuRequested not sending signal with QTreeWidget

  • Hi guys,

    I'm try to create a system where in a QTreeWidget, each item has its own right click menu. I know how to go about making the custom menus for each item however what i am struggling with is catching the signal which will run my function to create/update the right-click menus accordingly

    Here is my code:

    Header file
    private slots:
    void WorldItemMenu(const QPoint &point);
    CPP file
    (in the constructor)
    //World Panel
        connect(ui->TW_World, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(InterfaceWorldMenu(const QPoint &)));
    //Update the RightClick Menu
    void ZoneEditor::WorldItemMenu(const QPoint &point)
       // QModelIndex index = ui->TW_World->indexAt(point);
        qDebug() << "wassup dude";

    What should be happening is whenever i rightclick an item, the console output should say "wassup dude" however there is no output. Instead i get this

    "QObject::connect: No such slot ZoneEditor::InterfaceWorldMenu(const QPoint &)"

    Which has what has got be stumped because i made InterfaceWorldMenu a slot so how can it not find it?


  • Your slot in the connect is InterfaceWorldMenu(const QPoint &)) but the slot you defined is InterfaceWorldMenu(const QPoint &))
    so the slot in connect should have been WorldItemMenu(const QPoint &point)

  • wow okay now i feel like an idiot. Having said that i've fixed that, and yet the signal is still not going through. If i right click there is no "wassup dude" output.

  • show me your code?

  • Lifetime Qt Champion

    @Cysis145 In such situations you should check what connect(...) returns:

    qDebug() << connect(ui->TW_World, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(InterfaceWorldMenu(const QPoint &)));

    If it returns false then the connection failed. And if the connection fails you actually should see a warning at runtime.

Log in to reply