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. Cannot queue argument of type "QTextBlock"
Forum Updated to NodeBB v4.3 + New Features

Cannot queue argument of type "QTextBlock"

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 7.9k Views 1 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by Cobra91151
    #1

    Hi! I have decided to use QProgressDialog to monitor loading of big text file, but I have some issue with QProgressBar.

    Code:

        QProgressDialog progressDialog;
        progressDialog.setWindowTitle(QObject::tr("Test"));
        progressDialog.setFixedSize(350, 100);
        progressDialog.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
        progressDialog.setCancelButton(false);
    
        QProgressBar *progressBar = new QProgressBar(&progressDialog);
        progressBar->setTextVisible(false);
        progressDialog.setBar(progressBar);
        progressDialog.setMinimum(0);
        progressDialog.setValue(0);
        progressDialog.setMaximum(100);
        progressDialog.setLabelText(QObject::tr("Loading data. Please wait..."));
        QFutureWatcher<void> watcher;
        connect(&progressDialog, &QProgressDialog::canceled, &watcher, &QFutureWatcher<void>::cancel);
        connect(&watcher, &QFutureWatcher<void>::finished, &progressDialog, &QProgressDialog::reset);
        //connect(&watcher, &QFutureWatcher<void>::progressRangeChanged, &progressDialog, &QProgressDialog::setRange);
        connect(&watcher, &QFutureWatcher<void>::progressValueChanged, &progressDialog, &QProgressDialog::setValue);
        QFuture<void> future = QtConcurrent::run(this, &Test::loadDataFile);
        watcher.setFuture(future);
        progressDialog.exec();
        watcher.waitForFinished();
    
    void Test::loadDataFile()
    {
        ui->plainTextEdit->setPlainText(dbTextStream.readAll());
    }
    

    The problem is that it displays empty progress or when I use connect(&watcher, &QFutureWatcher<void>::progressRangeChanged, &progressDialog, &QProgressDialog::setRange); it displays a busy indicator. I want to display standard progressbar, like in the image below. Also I get warnings: QObject::connect: Cannot queue arguments of type 'QTextBlock' (Make sure 'QTextBlock' is registered using qRegisterMetaType().) QObject: Cannot create children for a parent that is in a different thread. (Parent is QTextDocument(0x5a28e48), parent's thread is QThread(0x8dbcc0), current thread is QThread(0x5a1f700) QObject::connect: Cannot queue arguments of type 'QTextCursor' (Make sure 'QTextCursor' is registered using qRegisterMetaType().) How to fix it?

    Image:
    alt text

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That question was unrelated to your other topic so I moved to its own thread.

      The error itself is pretty clear: QTextBlock is unknown to the Qt meta type system so you have to make it known to it.

      You should take a look at Qt's documentation for qRegisterMetaType for more information.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Cobra91151C 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        That question was unrelated to your other topic so I moved to its own thread.

        The error itself is pretty clear: QTextBlock is unknown to the Qt meta type system so you have to make it known to it.

        You should take a look at Qt's documentation for qRegisterMetaType for more information.

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

        @SGaist

        I have set but the progress in still not moving.

        qRegisterMetaType<QTextBlock>("QTextBlock");
        qRegisterMetaType<QTextCursor>("QTextCursor");
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you forgot the Q_DECLARE_METATYPE ?

          By the way, remove the string parameter from your qRegisterMetaType calls. That version of the function should only be used to register aliases.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Cobra91151C 1 Reply Last reply
          1
          • SGaistS SGaist

            Did you forgot the Q_DECLARE_METATYPE ?

            By the way, remove the string parameter from your qRegisterMetaType calls. That version of the function should only be used to register aliases.

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

            @SGaist

            I have changed to:

            qRegisterMetaType<QTextBlock>();
            qRegisterMetaType<QTextCursor>();
            

            but now I need to declare Q_DECLARE_METATYPE

            I have set it outsize the class in a header:

            Q_DECLARE_METATYPE(QTextBlock)

            But it displays error: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system

            Where I should declare Q_DECLARE_METATYPE?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Before your calls to qRegisterMetaType. You can do it in your main.cpp file before the main implementation.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Cobra91151C 1 Reply Last reply
              0
              • SGaistS SGaist

                Before your calls to qRegisterMetaType. You can do it in your main.cpp file before the main implementation.

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

                @SGaist

                Ok. I have registered it before class declaration in a header.
                Thanks.

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

                  Hi! I have fixed it by implementing QThread with worker class and passing the file name argument to QMetaObject::invokeMethod function and now I don't need to display the QProgressDialog.

                  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