Cannot queue argument of type "QTextBlock"



  • 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


  • Lifetime Qt Champion

    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.


Log in to reply