Ошибка QtConcurrent: в качестве инициализатора используется массив

я новичок в Qt, мне нужно использовать другой поток для функции-члена ниже

int length=interface->get_message(channelnumber_uint, &identifier, message, &can_flag_uint, timeout_uint);

я пробовал это:

QFuture <int> future = QtConcurrent::run(interface, &can_handler::get_message, channelnumber_uint, &identifier, message, &can_flag_uint, timeout_uint);
int length = future.result();

я получаю сообщение об ошибке в qtconcurrentfunctioncall.h

/usr/include/x86_64-linux-gnu/qt5/QtConcurrent/qtconcurrentstoredfunctioncall.h:1200: error: array used as initializer
     : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ }
                                                                                               ^

Я видел, что кто-то только что использовал std::array вместо массива без знака char, но мне не разрешено это менять. Есть ли другое решение?

целиком (я отрезал несвязанный код):

void MainWindow::on_pushButton_canreceivemessage_clicked()
        {
        QString channelnumber_qstr, timeout_qstr;
        unsigned int channelnumber_uint, timeout_uint, can_flag_uint, identifier, length;
        unsigned char message[8];

        channelnumber_qstr=ui->lineEdit_cancommunicationchannel->text();
        timeout_qstr=ui->lineEdit_cantimeoutreceive->text();
        channelnumber_uint = channelnumber_qstr.toUInt(&ok, 10);            
        timeout_uint = timeout_qstr.toUInt(&ok,10);

        //the function that has to be called from another thread  
        //int length=interface->get_message(channelnumber_uint, &identifier, message, &can_flag_uint, timeout_uint);

         QFuture <int> future = QtConcurrent::run(interface, &can_handler::get_message, channelnumber_uint, &identifier, message, &can_flag_uint, timeout_uint);
         int length = future.result();
         }

person StupidQuestioner    schedule 21.10.2019    source источник
comment
unsigned char message[8]; нельзя присвоить. std::array<> было бы нормальным решением c++, однако я не уверен, почему вы используете это в первую очередь.   -  person drescherjm    schedule 21.10.2019


Ответы (1)


я использовал функцию-оболочку:

int MainWindow::get_message_thread(int channel_number, unsigned int * identifier, string message_str, unsigned int * flag, unsigned int timeout)
    {
        unsigned char message_uch[8];

        int length=interface->get_message(channel_number, identifier, message_uch, flag, timeout);

         stringstream s;
         s << message_uch;
         message_str = s.str();
        return length;
    }

весь:

QString channelnumber_qstr, timeout_qstr;
        unsigned int channelnumber_uint, timeout_uint, can_flag_uint, identifier, length;
        string message;

        channelnumber_qstr=ui->lineEdit_cancommunicationchannel->text();
        timeout_qstr=ui->lineEdit_cantimeoutreceive->text();
        channelnumber_uint = channelnumber_qstr.toUInt(&ok, 10);            
        timeout_uint = timeout_qstr.toUInt(&ok,10);

QFuture <int> future = QtConcurrent::run(this, &MainWindow::get_message_thread, channelnumber_uint, &identifier, message, &can_flag_uint, timeout_uint);

    int length = future.result();
person StupidQuestioner    schedule 22.10.2019