Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebEngine process termination issue
QtWS25 Last Chance

QWebEngine process termination issue

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by
    #1

    Hi! I want to make QWebEngine access urls which requires the authentication. I have downloaded the simplebrowser as the example, and when I run http://192.168.0.1, it display the authentication dialog, but when I canceled and closed it, the simplebrowser displays issue:

    [11784:13720:0810/193655.735:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5)

    Code:

    void WebPage::handleAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *auth)
    {
        QWidget *mainWindow = view()->window();
        QDialog dialog(mainWindow);
        dialog.setModal(true);
        dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint);
    
        Ui::PasswordDialog passwordDialog;
        passwordDialog.setupUi(&dialog);
    
        passwordDialog.m_iconLabel->setText(QString());
        QIcon icon(mainWindow->style()->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mainWindow));
        passwordDialog.m_iconLabel->setPixmap(icon.pixmap(32, 32));
    
        QString introMessage(tr("Enter username and password for \"%1\" at %2")
                             .arg(auth->realm()).arg(requestUrl.toString().toHtmlEscaped()));
        passwordDialog.m_infoLabel->setText(introMessage);
        passwordDialog.m_infoLabel->setWordWrap(true);
    
        if (dialog.exec() == QDialog::Accepted) {
            auth->setUser(passwordDialog.m_userNameLineEdit->text());
            auth->setPassword(passwordDialog.m_passwordLineEdit->text());
        } else {
            // Set authenticator null if dialog is cancelled
            *auth = QAuthenticator(); // possible memory leak
        }
    }
    

    The same issue is also present in my project. During my simplebrowser testing I have noticed that such issue is only available when the dialog has been canceled. So is it memory leak? Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      *auth = QAuthenticator(); // possible memory leak

      It could leak but may not depending on how auth was allocated. It's definitely not good coding. And it could cause an issue if auth is then cleaned up with a delete or something. You should never modify what a pointer points to inside a function like that. Ownership of pointers should have a clear chain. The caller should own that pointer and it's memory.

      It it was allocated with new and has no parent object then it will leak. If it's on the stack or has a parent it will be fine.

      It's a very weird way to do it though. A bool return or an int or pretty much anything to indicate failure would be way better than messing with a pointer like that.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      Cobra91151C 1 Reply Last reply
      0
      • A ambershark

        *auth = QAuthenticator(); // possible memory leak

        It could leak but may not depending on how auth was allocated. It's definitely not good coding. And it could cause an issue if auth is then cleaned up with a delete or something. You should never modify what a pointer points to inside a function like that. Ownership of pointers should have a clear chain. The caller should own that pointer and it's memory.

        It it was allocated with new and has no parent object then it will leak. If it's on the stack or has a parent it will be fine.

        It's a very weird way to do it though. A bool return or an int or pretty much anything to indicate failure would be way better than messing with a pointer like that.

        Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by Cobra91151
        #3

        @ambershark

        Hi! Yes, I know it's weird. I tried to set auth = nullptr; but the dialog never closes. When I delete the object - delete auth; it crashes. QAuthenticator doesn't have deleteLater() method.

        Also I have tried detach method but still it never closes.

        This code is the only way to close the dialog: *auth = QAuthenticator(); but it will cause the [11784:13720:0810/193655.735:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5) issue. So how to fix it?

        A 1 Reply Last reply
        1
        • Cobra91151C Cobra91151

          @ambershark

          Hi! Yes, I know it's weird. I tried to set auth = nullptr; but the dialog never closes. When I delete the object - delete auth; it crashes. QAuthenticator doesn't have deleteLater() method.

          Also I have tried detach method but still it never closes.

          This code is the only way to close the dialog: *auth = QAuthenticator(); but it will cause the [11784:13720:0810/193655.735:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5) issue. So how to fix it?

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @Cobra91151 Oh I see, you are having issues with the window not closing?

          Also you don't want to mess with auth pointer at all. Like I said it's expected to be handled outside that function.

          The window should be closed by the time you get to that else {} clause though. If it's not closing that is concerning. Can you show a video of it happening?

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          Cobra91151C 2 Replies Last reply
          0
          • A ambershark

            @Cobra91151 Oh I see, you are having issues with the window not closing?

            Also you don't want to mess with auth pointer at all. Like I said it's expected to be handled outside that function.

            The window should be closed by the time you get to that else {} clause though. If it's not closing that is concerning. Can you show a video of it happening?

            Cobra91151C Offline
            Cobra91151C Offline
            Cobra91151
            wrote on last edited by
            #5

            @ambershark

            I have changed the code.

            if (dialog.exec() == QDialog::Accepted) {
                    auth->setUser(passwordDialog.m_userNameLineEdit->text());
                    auth->setPassword(passwordDialog.m_passwordLineEdit->text());
             } else {
                    // Set authenticator null if dialog is cancelled
                    //*auth = QAuthenticator();
                    auth->setUser(QString());
                    auth->setPassword(QString());
                    auth = nullptr;
             }
            

            I will create the gif animation to illustrate the issue.

            1 Reply Last reply
            0
            • A ambershark

              @Cobra91151 Oh I see, you are having issues with the window not closing?

              Also you don't want to mess with auth pointer at all. Like I said it's expected to be handled outside that function.

              The window should be closed by the time you get to that else {} clause though. If it's not closing that is concerning. Can you show a video of it happening?

              Cobra91151C Offline
              Cobra91151C Offline
              Cobra91151
              wrote on last edited by Cobra91151
              #6

              @ambershark

              So here is the issue when dialog never closes:
              Issue

              Also, when else clause is removed from the code, the same issue is still present. By the way, I can't set the parent to QAuthenticator because it only accepts const QAuthenticator &other as the parent and also default constructor is available. I think that I will try to re-implement it, to add some custom methods/constructors to the class.

              A 1 Reply Last reply
              0
              • Cobra91151C Cobra91151

                @ambershark

                So here is the issue when dialog never closes:
                Issue

                Also, when else clause is removed from the code, the same issue is still present. By the way, I can't set the parent to QAuthenticator because it only accepts const QAuthenticator &other as the parent and also default constructor is available. I think that I will try to re-implement it, to add some custom methods/constructors to the class.

                A Offline
                A Offline
                ambershark
                wrote on last edited by
                #7

                @Cobra91151 Ok that makes a lot more sense.. So the dialog is indeed closing but it is immediately coming back up since the function is called again right away to get authentication.

                So along those lines what is calling handleAuthenticationRequired? What you want to do is only call that once and then maybe proceed to an 403 page when it fails rather than continually calling it.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                Cobra91151C 1 Reply Last reply
                0
                • A ambershark

                  @Cobra91151 Ok that makes a lot more sense.. So the dialog is indeed closing but it is immediately coming back up since the function is called again right away to get authentication.

                  So along those lines what is calling handleAuthenticationRequired? What you want to do is only call that once and then maybe proceed to an 403 page when it fails rather than continually calling it.

                  Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on last edited by
                  #8

                  @ambershark

                  It connects here in simplebrowser project:

                  WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
                      : QWebEnginePage(profile, parent)
                  {
                      connect(this, &QWebEnginePage::authenticationRequired, this, &WebPage::handleAuthenticationRequired);
                      connect(this, &QWebEnginePage::proxyAuthenticationRequired, this, &WebPage::handleProxyAuthenticationRequired);
                  }
                  

                  When *auth = QAuthenticator(); is set and dialog has been canceled I got:

                  0_1533975552605_2018-08-11_111828.png

                  1 Reply Last reply
                  0
                  • Cobra91151C Offline
                    Cobra91151C Offline
                    Cobra91151
                    wrote on last edited by
                    #9

                    Also I have noticed that the process exits normal, maybe the leak is in my code. I will check and reply later.

                    1 Reply Last reply
                    0
                    • Cobra91151C Offline
                      Cobra91151C Offline
                      Cobra91151
                      wrote on last edited by Cobra91151
                      #10

                      So my code:

                       connect(browser->page(), &QWebEnginePage::authenticationRequired, [this](const QUrl &url, QAuthenticator *authenticator) {
                              WebAuthenticator *webAuthDialog = new WebAuthenticator(browser->page()->view()->window());
                              connect(this, &Test::authInfo, webAuthDialog, &WebAuthenticator::setAuthInfo);
                              connect(webAuthDialog, &WebAuthenticator::authenticationData, [this, authenticator, webAuthDialog](QString user, QString password) {
                                  if (!user.isEmpty() || !password.isEmpty()) {
                                      authenticator->setUser(user);
                                      authenticator->setPassword(password);
                                  } else {
                                      QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("Please enter your credentials to sign in!"), QMessageBox::Ok);
                                  }
                      
                                  webAuthDialog->close();
                                  webAuthDialog->deleteLater();
                              });
                              connect(webAuthDialog, &WebAuthenticator::authenticationCanceled, [this, authenticator, webAuthDialog]() {
                                  webAuthDialog->close();
                                  webAuthDialog->deleteLater();
                                  *authenticator = QAuthenticator();
                                  qDebug() << "Test";
                              });
                              emit authInfo(url, authenticator, qApp->style()->standardIcon(QStyle::SP_MessageBoxQuestion));
                              webAuthDialog->exec();
                          });
                      

                      WebAuthenticator is the GUI dialog, it has setAttribute(Qt::WA_DeleteOnClose); so it will be deleted when closed. The code leads to the issue: [13628:8812:0811/120557.720:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5)
                      Any ideas how to fix it? Thanks.

                      1 Reply Last reply
                      0
                      • Cobra91151C Offline
                        Cobra91151C Offline
                        Cobra91151
                        wrote on last edited by
                        #11

                        This issue [13628:8812:0811/120557.720:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5) is only in debug mode. Maybe it's the default behavior? Thanks.

                        1 Reply Last reply
                        0
                        • Cobra91151C Offline
                          Cobra91151C Offline
                          Cobra91151
                          wrote on last edited by Cobra91151
                          #12

                          So, my code works, I have tried it on the different project. The problem is, when some leak/issue was occurred in the QWebEngine process, it will fail to close the process and display the issue: [13628:8812:0811/120557.720:ERROR:process_win.cc(135)] Unable to terminate process: Access is denied. (0x5) even when the leak/issue has been fixed.

                          1 Reply Last reply
                          0
                          • Cobra91151C Offline
                            Cobra91151C Offline
                            Cobra91151
                            wrote on last edited by
                            #13

                            Yes, I was right. I have deleted the cache and QWebEngine directory from the local dir repository, shut down the PC for about 3 hours, then booted, started the project and checked the issue. Now the QWebEngine process exits successfully sometimes in debug mode. I think the issue is resolved. Thank you.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved