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. QTextBrowser link opens Notepad on Windows ???

QTextBrowser link opens Notepad on Windows ???

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 104 Views 2 Watching
  • 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.
  • B Offline
    B Offline
    BastienSante
    wrote last edited by
    #1

    Hello everyone,

    I'm facing a problem with the Windows version of my MD editor / browser, using links. I am using the links to navigate between pages in a folder.

    On Linux, when the links are clicked, the new page simply displays in the QTextBrowser as intended. However on Windows, Notepad opens.

    a44cdfc9-2951-4865-ae41-17dc94f6e7a8-image.png

    Here is the method I wrote to handle clicking links :

    void Editor::FollowLink(const QUrl& followedFile){
    
        QUrl resolvedURL = GetCurrentTab()->document->baseUrl().resolved(followedFile);
        qDebug() << "The resolved URL is" << resolvedURL.toString();
    
        QString filePath(resolvedURL.toString());
        qDebug() << filePath;
    
    
        if(!filePath.isEmpty()) {
    
            QFile openedFile(filePath);
    
            if(!openedFile.exists()) {
                qDebug() << filePath << " does not exist.";
                    return;
            }
    
            if (!(openedFile.open(QIODeviceBase::ReadWrite))) {
                qDebug() << "Error : File could not be opened";
                return;
            }
    
            GetCurrentTab()->renderDocument->setBaseUrl(resolvedURL);
            GetCurrentTab()->document->setBaseUrl(resolvedURL);
            GetCurrentTab()->editor->setPlainText(openedFile.readAll());
            GetCurrentTab()->browser->setSource(resolvedURL);
            GetCurrentTab()->RenderDocument();
    
            openedFile.close();
        }
        SetTabTitle(filePath);
    }
    

    My browser widget has setOpenExternalLinks(true). Moreover, Notepad is not set as the default application for Markdown, but manages to "steal" the file opening from my app ?

    What could be happening here ? Thanks for your answers !

    jeremy_kJ 1 Reply Last reply
    0
    • B BastienSante

      Hello everyone,

      I'm facing a problem with the Windows version of my MD editor / browser, using links. I am using the links to navigate between pages in a folder.

      On Linux, when the links are clicked, the new page simply displays in the QTextBrowser as intended. However on Windows, Notepad opens.

      a44cdfc9-2951-4865-ae41-17dc94f6e7a8-image.png

      Here is the method I wrote to handle clicking links :

      void Editor::FollowLink(const QUrl& followedFile){
      
          QUrl resolvedURL = GetCurrentTab()->document->baseUrl().resolved(followedFile);
          qDebug() << "The resolved URL is" << resolvedURL.toString();
      
          QString filePath(resolvedURL.toString());
          qDebug() << filePath;
      
      
          if(!filePath.isEmpty()) {
      
              QFile openedFile(filePath);
      
              if(!openedFile.exists()) {
                  qDebug() << filePath << " does not exist.";
                      return;
              }
      
              if (!(openedFile.open(QIODeviceBase::ReadWrite))) {
                  qDebug() << "Error : File could not be opened";
                  return;
              }
      
              GetCurrentTab()->renderDocument->setBaseUrl(resolvedURL);
              GetCurrentTab()->document->setBaseUrl(resolvedURL);
              GetCurrentTab()->editor->setPlainText(openedFile.readAll());
              GetCurrentTab()->browser->setSource(resolvedURL);
              GetCurrentTab()->RenderDocument();
      
              openedFile.close();
          }
          SetTabTitle(filePath);
      }
      

      My browser widget has setOpenExternalLinks(true). Moreover, Notepad is not set as the default application for Markdown, but manages to "steal" the file opening from my app ?

      What could be happening here ? Thanks for your answers !

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote last edited by
      #2

      @BastienSante said in QTextBrowser link opens Notepad on Windows ???:

      Here is the method I wrote to handle clicking links :

      Unfortunately, based on the problem statement, this is code that isn't executed. That doesn't help clarify what is executed.

      My browser widget has setOpenExternalLinks(true). Moreover, Notepad is not set as the default application for Markdown, but manages to "steal" the file opening from my app ?

      What could be happening here ? Thanks for your answers !

      QTextBrowser::openExternalLinks:

      Specifies whether QTextBrowser should automatically open links to external sources using QDesktopServices::openUrl() instead of emitting the anchorClicked signal. Links are considered external if their scheme is neither file or qrc.

      Did you intend to set openExternalLinks to false?

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      3

      • Login

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