Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. cannot get clipboard text using QClipboard on Android when App in background
Forum Updated to NodeBB v4.3 + New Features

cannot get clipboard text using QClipboard on Android when App in background

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 3 Posters 885 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.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by redstoneleo
    #1

    I am using the following code to retrieve clipboard text once clipboard data changed on Android

    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    
    
    class EngkuDict(QLabel):
        # Permissions QFile::​permissions() const
    
        def __init__(self, parent=None):
            super().__init__(parent)
            self.showMaximized()
    
            self.clipboard = QGuiApplication.clipboard()
            self.clipboard.dataChanged.connect(self.clipboardTextChanged)
            # self.clipboard.changed.connect(self.clipboardModeChanged)
    
        @pyqtSlot()
        def clipboardTextChanged(self):
            selectedText = self.clipboard.text()
            self.setText('clipboardTextChanged: {}'.format(selectedText))
    
        def clipboardModeChanged(self, mode):
    
            selectedText = self.clipboard.text()
            self.setText('mode: {}\n{}'.format(mode, selectedText))
    
    
    if __name__ == "__main__":
        import sys
        app = QApplication(sys.argv)
        # QApplication.setQuitOnLastWindowClosed(False)
    
        trayIcon = EngkuDict()
        trayIcon.show()
        sys.exit(app.exec_())
    

    when the code is running in background, I copied text in another application, this application just cannot get clipboard text, so how to solve the issue ?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Add a slot handling for QGuiAppllication::applicationStateChanged. When it changes to Qt::ApplicationActive, call QClipboard::text() to update the value.

      (Z(:^

      1 Reply Last reply
      1
      • R Offline
        R Offline
        redstoneleo
        wrote on last edited by
        #3

        Thanks ! But I want it to work constantly in the background even when not activated .

        jsulmJ 1 Reply Last reply
        0
        • R redstoneleo

          Thanks ! But I want it to work constantly in the background even when not activated .

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @redstoneleo Apps in background are stopped, aren't they? You would need a background service.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          5

          • Login

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