Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9032947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:06:16+00:00 2026-06-16T08:06:16+00:00

Please take a look at this picture: You can see a QTableView with some

  • 0

Please take a look at this picture:

enter image description here

You can see a QTableView with some stupid content and a context menu in the center of it. My issue is if I click the table (no matter which button was pressed) view when that context menu is on (and I expect the context menu to disappear as it happens in Windows program and then appear back in a new place if the right button was pressed) my program immediately crash. I create it like this:

 connect(tableView, SIGNAL(customContextMenuRequested(const QPoint&)),
              this, SLOT(showContextMenu(const QPoint&)));

void MainWindow :: showContextMenu(const QPoint &_point)
{
   QPoint      pos   = tableView->mapToGlobal(_point);
   QModelIndex index = tableView->currentIndex();
   int         row   = index.row();

   QMenu menu;
   menu.addAction("Test 1");
   menu.addAction("Test 2");

   QAction *action =  menu.exec(pos);
   QString text    = action->text();

   if (text == "Test 1")
      qDebug("Test 1");
   else
      if (text == "Test 2")
          qDebug("Test 2");
   else
      qDebug("Vzdroch");
 }

I have no idea why it crashes. There’s no such thing as debugger in QtCreator, i.e. it is but installing it is as complicated as launching a rocket to space. What I need is just to handle mouse clicks beyond context menu area as I normally do.

I understand that it might be really difficult for you to find out why it crashes, so I’m gonna ease my question a bit. Is there a way to make that context menu disappear when the mouse goes beyond its area? There’s a signal named hovered() in Qt. It is emitted when user mouse is over a widget, so I was searching for a signal, let’s call it unhovered(), emitted when user takes mouse off a widget. Unfortunately I failed to find such a signal. Is there a way to let my program know that mouse is off?

Hope I’ve described my issue fully.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:06:17+00:00Added an answer on June 16, 2026 at 8:06 am

    QMenu::exec returns 0 if no menu item was selected.

    You need to check action before you dereference it, otherwise you’ll dereference a null pointer which leads to undefined behavior.

    QAction *action =  menu.exec(pos);
    if (!action) {
      qDebug() << "no menu selected";
    } else {
      QString text  = action->text();
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please take a look at this fiddle jsfiddle.net/Qstuw/2/ As you see from picture first
Please take a look at this fiddle: http://jsfiddle.net/hughbe/QYGcq/ As you can see, the label
Please take a look at this table : http://www.mediawiki.org/wiki/Manual:Logging_table As you can see wikipedia
Please take a look at this navigation: http://beta.viewcms.info/mint/ And you can see the hover
can someone take a look at this please http://jsfiddle.net/bloodygeese/ecscY/56/ it looks like I have
Please take a look at this topic : Can I calculate the average of
Please take a look at THIS page. Please feed in some random data and
Please take a look at this fiddle . <h2><span>Some Text</span></h2> I'm trying to vertically
Can you please take a look at this Demo in jsFiddle and let me
Hi could some one please take a look at this and let me know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.