Skip to content
  • 0 Votes
    2 Posts
    339 Views
    timob256T

    @timob256 In general , there was one mistake , for some reason I thought that by setting the size of the vector , it would correct everything itself , but it turned out not to be so

    void MainWindow::slotProcessDatagrams() { QByteArray baDatagram_in; do { baDatagram_in.resize(m_pudp_in->pendingDatagramSize()); m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size()); } while(m_pudp_in->hasPendingDatagrams()); QDataStream in(&baDatagram_in, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_5_3); in >> str_priem; // принимаем сообщение str_x = str_priem.section(' ',0,0); str_y = str_priem.section(' ',1); if(my_int >= 80) { // clear firs element // x.pop_back(); // y.pop_back(); // x.removeLast(); // y.removeLast(); x.pop_front(); //последний из вектора y.pop_front(); x << str_x.toDouble(); y << str_y.toDouble(); } else { x << str_x.toDouble(); y << str_y.toDouble(); my_int = my_int + 1; } // чистим старое отрисовываем новое wGraphic->graph(0)->clear(); wGraphic->graph(0)->rescaleAxes(); // wGraphic->replot(); // Отрисовываем содержимое полотна wGraphic->graph(0)->setData(y,x); // Устанавливаем координаты точек графика wGraphic->replot(); // Отрисовываем содержимое полотна // Очищаем принятую строку str_priem.clear(); }

    True, a new error jumped (for some reason the last and first point somehow connects, I don't know how to break)

    введите сюда описание изображения

  • 0 Votes
    3 Posts
    274 Views
    C

    @MEsc said in Accessing value of vector only once:

    I have another function MainWindow::on_start_clicked()
    When this Function get called (here via button),
    values should load in vec.
    QVector<QString> vec = loadfrom();

    That looks like vec is a variable local to the slot attached to the button. You load it and then it is destroyed when the slot exits. If you want the vec object to have a longer lifetime then you need to arrange that. As @Christian-Ehrlicher says, making vec a private member variable of the MainWindow class is probably the right approach. So,

    class MainWindow: public QMainWindow { ... private: QVector<QString> m_vec }; void MainWindow::on_start_clicked() { ... m_vec = loadfrom(); ... } void MainWindow::on_answer_returned() { ... // do stuff with m_vec ... }

    This is basic C++ knowledge and not Qt specific.

  • 0 Votes
    4 Posts
    494 Views
    Chris KawaC

    There are examples and detailed descriptions on both pages I linked.

  • 0 Votes
    3 Posts
    333 Views
    K

    @jsulm Thank you. That works. What could have been the problem? That C Arrays are not compatible for the container classes?

  • 0 Votes
    48 Posts
    17k Views
    H

    Hi I've done something recently I've needed so my approach was:

    total_len = qimg.width() * qimg.height(); std::vector<unsigned int> data; data.reserve(total_len); for(int i=0; i < qimg.height(); i++) for(int j=0; j < qimg.width(); j++){ data.push_back(qimg.pixel(j, i)); }

    I needed it as an rgb pixels in order to do some image manipulations, but I believe you can also take the uchar data.

  • 0 Votes
    7 Posts
    2k Views
    M

    @mrjj
    Thank you guys very much!

  • 0 Votes
    7 Posts
    1k Views
    SGaistS

    Rather than using a bunch of ifs, what about using a QMap or a QHash to store the information and retrieve that in the slot ? This will make your implementation easier to maintain.

  • 0 Votes
    3 Posts
    2k Views
    L

    that solved it! Thanks!

  • 0 Votes
    15 Posts
    14k Views
    6thC6

    Oh hey. Didn't see you were still stuck.

    So if you've QML declared your (LineSeries, ScatterSeries, and SplineSeries) - in C++ you'd have a slot (or Q_INVOKABLE) receive the object as a QXYSeries* ptr.

    Once you have access to a QXYSeries object: (you have a pointer to your series and you know which c++ std::vector matches what series etc) the only work you have to do is reformat your std::vector into a QVector<QPointF> before the replace() call of the QLineSeries*

    The LineSeries will do the work to repaint.
    I guess it signals: void QXYSeries::pointsReplaced() which kicks of some ChartView dirty or repaint request. Anyhow, it's free to us.

  • 0 Votes
    2 Posts
    1k Views
    mrjjM

    Hi
    Just create a function and use that instead of new directly

    QComboBox * MakeDefaultCB(QObject *Parent) { QComboBox * cur= new QComboBox (Parent); cur->addItem(QString("defect 1")); cur->addItem(QString("defect 2")); ... return cur; } dbox1.push_back(MakeDefaultCB(this));
  • 0 Votes
    3 Posts
    2k Views
    TommyXT

    @Wieland

    Thank you so much! I added QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); when the object was created, and this apparently solves the problem :)

  • 0 Votes
    6 Posts
    4k Views
    AslundA

    Hello guys

    Thanks a lot for the answers.
    Your replies got me thinking and I recalled how includes can mess things up.
    I removed a couple of the include files in some of my header files that turned out to be unnecessary.
    After removing all the header files while still being able to compile then the program was running again perfectly.

    Regards
    Sebastian Aslund