Results 1 to 6 of 6

Thread: Application crashes on click of a QLabel that is set to open URL in browser

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Application crashes on click of a QLabel that is set to open URL in browser

    I have a pop-up widget that shows on entering a specific cell of QTableWidget. And I'm closing the pop-up window on leave event.
    The pop-up widget has got some QLabels, which are set as URLs. When I click on a hyperlink(QLabel), the link is opened in my browser. And when I click on another url Qlabel, the link is opened, but my application crashes immediately.

    One observation is if the mouse is taken out of the pop-up window, before it takes time to open the link in the browser, the application doesn't crash.

    Qt Code:
    1. //cpopupwindow.h
    2. // this closes the window when the mouse is out of widget
    3. protected:
    4. bool eventFilter(QObject * object, QEvent * event)
    5. {
    6. if(event->type() == QEvent::Leave)
    7. {
    8. if(isVisible())
    9. {
    10. while(!cveReferences.isEmpty())
    11. {
    12. delete cveReferences.takeFirst();
    13. }
    14. this->close();
    15. }
    16. }
    17.  
    18. return QWidget::eventFilter(object, event);
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // in cpopupwindow.cpp
    2. this->installEventFilter(this); //in ctor
    3.  
    4. // this is a public function which displays the content and is called in tablewidget class on cellEnter()
    5. void CPopupWindow::someFunction()
    6. {
    7. // This is how I add the text to QLabels
    8. if("CVE" == repoType)
    9. {
    10. cceReference_table->setVisible(false);
    11. for(int i = 0; i < lst.count(); i++)
    12. {
    13. cveReferences.append(new QLabel());
    14. cveReferences.at(i)->setText("<a href=\"" + references.value(lst.at(i)) + "\">" +
    15. lst.at(i) + "</a>");
    16. cveReferences.at(i)->setTextFormat(Qt::RichText);
    17. cveReferences.at(i)->setTextInteractionFlags(Qt::TextBrowserInteraction);
    18. cveReferences.at(i)->setOpenExternalLinks(true);
    19. vLyt->addWidget(cveReferences.at(i));
    20. }
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    Everything is fine until second click of the URL. On second click, if the mouse is not taken out of pop-up widget, then the whole application crashes.
    Kindly help me with this. Thank you.
    Last edited by rawfool; 16th June 2013 at 23:15.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Application crashes on click of a QLabel that is set to open URL in browser

    Run your program in your debugger and cause it to crash. When it crashes look through the stack back trace to find the line in your code that is causing the crash. We cannot do this for you.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Application crashes on click of a QLabel that is set to open URL in browser

    I'm not emitting any signals on click of the QLabel, just setting the QLabel as hyperlink and setting flags to Qt::TextBrowserInteraction as shown in someFunction() in earlier post. Thing is, this crash happens only if the mouse is not oved out of this window, the browser shows on top of it, this point crash happens. But if I quickly remove my mouse out of widget, event closes the window.

    So I'm unable to figure out where I put the break-point. As the hyperlinked labels are already set on the window & there is no problem there.
    Thank you.

    EDIT: I put the break-point on show of this pop-up window, it's crashing and stack message is
    Qt Code:
    1. Level Function File Line
    2. 0 QApplicationPrivate::dispatchEnterLeave Qt5Widgets
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 17th June 2013 at 07:34.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Application crashes on click of a QLabel that is set to open URL in browser

    while(!cveReferences.isEmpty())
    {
    delete cveReferences.takeFirst();
    }
    Why are you deleting cveReferences?


    for(int i = 0; i < lst.count(); i++)
    {
    cveReferences.append(new QLabel());
    cveReferences.at(i)->setText("<a href=\"" + references.value(lst.at(i)) + "\">" +
    lst.at(i) + "</a>");
    cveReferences.at(i)->setTextFormat(Qt::RichText);
    cveReferences.at(i)->setTextInteractionFlags(Qt::TextBrowserInteractio n);
    cveReferences.at(i)->setOpenExternalLinks(true);
    vLyt->addWidget(cveReferences.at(i));
    }
    It is not garanteed that you are setting the QLabel you just created. It is better to set the QLabel settings and then append it to the list. Just think what if the list was not empty, and you keep addeing new QLabels, then you will end up setting the old QLabels
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Application crashes on click of a QLabel that is set to open URL in browser

    This, pop-up window is basically shown on cellEntered() of a tablewidget. I'm deleting that cveReferences because there is one else if more condition in someFunction() where some other widget comes in place of Qlabels. I'm adding & deleting the Qlabels dynamically, based on a reply from QNetworkReply.
    So the adding & deleting of these QLabels needs to be dynamic in order to hide these labels to give place for another widget on other event.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Application crashes on click of a QLabel that is set to open URL in browser

    Quote Originally Posted by rawfool View Post
    So I'm unable to figure out where I put the break-point.
    You don't need to set a breakpoint. Let the program crash and the debugger will stop your program and display a back trace. Follow the back trace down until you find the line of your code that triggered the crash. In all likelihood at that point in your code you are accessing a null or invalid pointer.

Similar Threads

  1. Hyperlink text in QLabel to open web browser
    By qt_developer in forum Qt Programming
    Replies: 7
    Last Post: 4th October 2018, 07:47
  2. Replies: 0
    Last Post: 8th May 2012, 14:29
  3. Replies: 0
    Last Post: 17th March 2011, 04:17
  4. How to open a browser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2006, 19:21
  5. open a browser
    By npc in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 11:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.