Skip to content
  • 0 Votes
    3 Posts
    515 Views
    D

    @Dean21 I just figured this out myself and am just posting in case someone else has the same issue.

    My function where I want the timer now looks like shown below:

    QObject::connect(&client, &QMMqttClient::onMessageReceived, [this](const QString &topic, const QByteArray &msg) { ui->Alarm_Triggered_Label->setText("Temperature alarm of PSU triggered, HV output disabled for 5 minutes"); ui->HV_ON_OFF_Button->setEnabled(false); // Use QMetaObject::invokeMethod to execute the code in the main GUI thread QMetaObject::invokeMethod(this, "publishAfterDelay", Qt::QueuedConnection); });

    And the call to function publishAfterDelay() looks like shown below:

    void Widget::publishAfterDelay() { QTimer::singleShot(3000, this, [this]() { client.publishMesage("Alarm_5_min_cooldown_complete", "1"); qDebug() << "timer pinged"; }); }

    Hope this helps anyone else.

  • 0 Votes
    7 Posts
    1k Views
    T

    @Christian-Ehrlicher Yup.. it worked when i upgraded my Qt version. Thanks a lot.

    Just for education purposes, can i ask lets say if i am still using qt 5.8.0 and i wish to remove this message. Is there a way to do that? I believe this message is caused by this qt sqldriver file called qsql_psql.cpp. So I tried to remove the code that prompts this message in qsql_psql.cpp file and it didnt work when i run my application.

  • 0 Votes
    3 Posts
    475 Views
    B

    @SGaist This is the solution! Thank you very much. Below is my new setData() and TextEdited()

    setData()

    bool SummaryModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { SetSummaryQuantity(value.toInt()); emit dataChanged(index,index); return true; } else { return false; } return false; }

    TextEdited()

    void QueriesCreator::on_quantityGeneralInformationLineEdit_textEdited(const QString &arg1) { calculations.SetMaterialQuantity(ui->quantityGeneralInformationLineEdit->text().toInt()); CalculateMaterialCostInZloty(); summaryModel->setData(ui->summaryDefaultTableView->model()->index(6,0),ui->quantityGeneralInformationLineEdit->text().toInt(),Qt::EditRole); }

    and of course the data()

    QVariant SummaryModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { //Quantity if (index.row() == 0 && index.column() == 0) return QString("50"); if (index.row() == 2 && index.column() == 0) return QString("100"); if (index.row() == 4 && index.column() == 0) return QString("1000"); if (index.row() == 6 && index.column() == 0) return GetSummaryQuantity(); //Currency- byc w moze w przyszlosci zmienic na inne if (index.row() == 0 && index.column() == 1) return QString("PLN"); if (index.row() == 1 && index.column() == 1) return QString("EUR"); if (index.row() == 2 && index.column() == 1) return QString("PLN"); if (index.row() == 3 && index.column() == 1) return QString("EUR"); if (index.row() == 4 && index.column() == 1) return QString("PLN"); if (index.row() == 5 && index.column() == 1) return QString("EUR"); if (index.row() == 6 && index.column() == 1) return QString("PLN"); if (index.row() == 7 && index.column() == 1) return QString("EUR"); //Price Placeholders //Material if (index.row() == 0 && index.column() == 2) return QString("0,00"); if (index.row() == 1 && index.column() == 2) return QString("0,00"); if (index.row() == 2 && index.column() == 2) return QString("0,00"); if (index.row() == 3 && index.column() == 2) return QString("0,00"); if (index.row() == 4 && index.column() == 2) return QString("0,00"); if (index.row() == 5 && index.column() == 2) return QString("0,00"); if (index.row() == 6 && index.column() == 2) return QString("0,00"); if (index.row() == 7 && index.column() == 2) return QString("0,00"); //Machining if (index.row() == 0 && index.column() == 3) return QString("0,00"); if (index.row() == 1 && index.column() == 3) return QString("0,00"); if (index.row() == 2 && index.column() == 3) return QString("0,00"); if (index.row() == 3 && index.column() == 3) return QString("0,00"); if (index.row() == 4 && index.column() == 3) return QString("0,00"); if (index.row() == 5 && index.column() == 3) return QString("0,00"); if (index.row() == 6 && index.column() == 3) return QString("0,00"); if (index.row() == 7 && index.column() == 3) return QString("0,00"); //Diference if (index.row() == 0 && index.column() == 4) return QString("0,00"); if (index.row() == 1 && index.column() == 4) return QString("0,00"); if (index.row() == 2 && index.column() == 4) return QString("0,00"); if (index.row() == 3 && index.column() == 4) return QString("0,00"); if (index.row() == 4 && index.column() == 4) return QString("0,00"); if (index.row() == 5 && index.column() == 4) return QString("0,00"); if (index.row() == 6 && index.column() == 4) return QString("0,00"); if (index.row() == 7 && index.column() == 4) return QString("0,00"); } if(role==Qt::TextAlignmentRole) { return Qt::AlignCenter; } return QVariant(); }

    Now It works as I expect. Thanks and Have a good day!

  • 0 Votes
    5 Posts
    430 Views
    O

    @JonB

    But you talk about "The purpose is to have different lines/coloring for each line". That implies to me you do want multiple, separate line series, each with their own points and color?

    Yes.

    In that case you do want new QLineSeries created each time round the loop, so you end up with 5 lines (and get rid of the wasted one outside the loop).

    Okay, thank you. I did this and with a little bit of refactoring I got it to work as expected. Appreciate the assistance!

  • 0 Votes
    3 Posts
    1k Views
    B

    It's the same with me...

  • 0 Votes
    1 Posts
    414 Views
    No one has replied
  • 1 Votes
    15 Posts
    17k Views
    Christian EhrlicherC

    @osirisgothra this is a last warning - stop reviving old posts.

  • 0 Votes
    12 Posts
    3k Views
    T

    @Christian-Ehrlicher said in How avoid memory leak with GUI programming:

    @TheEnigmist said in How avoid memory leak with GUI programming:

    VS points to p = p.scaled line that add every time 10k byte of data (50x50x4 bytes), and each time I create and detroy the widget where that QAbstractTableModel is I see in memory that all that Pixmap are never destroyed.

    There is no leak and can't be one - you should take a look into QPixmapCache and for the sake of performance and implicit sharing don't load the pixmap in your data() method every time.

    Yeah I just found out that I was really wrong with that :( I will fix it right now!
    So I can go over when see pixmap in my allocated memory due to QPixmapCache. Ofc is always better to improve my code and don't load so many times a pixmap!

    @Chris-Kawa said in How avoid memory leak with GUI programming:

    @TheEnigmist said in How avoid memory leak with GUI programming:

    So if I'm not wrong what is cached is not the file on disk, but its scaled version

    No. How would Qt know that it's the same pixmap? What's cached is the pixmap that you create from a file, and the path (with some additional info) becomes a key to look it up in the cache.

    I see, but why the debugger points me to the scaled() function when looking for the allocated memory istance?

  • 0 Votes
    15 Posts
    3k Views
    JoeCFDJ

    @SeeRich
    can you change

    setAttribute(Qt::WA_StyledBackground); setObjectName( "mainWindow" ); setStyleSheet( QString( "MainWindow#%1 { background-color: blue; }" ) .arg( objectName() );

    to

    setAttribute(Qt::WA_StyledBackground); setObjectName( "mainWindow" ); setStyleSheet( QString( "QWidget#%1 { background-color: blue; }" ) .arg( objectName() );

    there is no MainWindow stylesheet. It should be QMainWindow.

  • 0 Votes
    23 Posts
    3k Views
    Kent-DorfmanK

    @JonB said in converting from float or double to QString results in output being 0:

    Warning: The QString content may only contain valid numerical characters which includes the plus/minus sign, the character e used in scientific notation, and the decimal point. Including the unit or additional characters leads to a conversion error.

    In which case RTFM is the rule of the day! but I'm lazy.

  • 0 Votes
    18 Posts
    1k Views
    D

    @jsulm the data that is sent is in the form of a char array, example,

    char message[] = "message here";

    I use QString because before I was using std::string and I was getting errors when trying to submit that to the line edit, I think conversion type errors, using a QString removed that error and thus I just stuck with it.

    edit: oh it is working now, I feel like we didnt change anything though and we were just going through debug statements

  • 0 Votes
    24 Posts
    3k Views
    jsulmJ

    @Dean21 Please show your current code if something does not work...

  • Installing MQTT module

    Unsolved General and Desktop
    11
    0 Votes
    11 Posts
    4k Views
    jsulmJ

    @Dean21 @JoeCFD asked where the mqtt libs you built are stored, not where the code is...

  • 0 Votes
    3 Posts
    699 Views
    D

    @SGaist Great Thank you this, I know that qt has its own MQTT module just I had already developed my code for MQTT using the mosquitto library before I knew I was going to be making a GUI using QT.

  • QVariant to QList

    Solved General and Desktop
    13
    0 Votes
    13 Posts
    2k Views
    mzimmersM

    @JoeCFD said in QVariant to QList:

    Understand. Thiink about you can never be number 1 anymore if you play chess.

    Oddly enough, that was never a concern of mine.

  • 0 Votes
    4 Posts
    1k Views
    SGaistS

    Then the links I posted is what you should read and use.

  • 0 Votes
    5 Posts
    1k Views
    T

    At the end I've researched again the view's transformations and concluded to support both features and warn for the complexity.

    I did not re-implement the add/remove items of the scene together with a group. Thanks for the hint @Asperamanca .

  • 0 Votes
    2 Posts
    311 Views
    JonBJ

    @harveyab said in Show build kit at runtime:

    use it for conditional compilation

    If you want to use it for this you will need to know at compile-time, not at runtime.

    Assuming (I don't know but would guess) that you cannot access the particular kit selected in Creator I would expect to have to test for compile-time defines which come from the kit chosen, e.g. compiler version like _MSC_VER.

  • 0 Votes
    8 Posts
    949 Views
    JonBJ

    @Uchi
    Correct! At the time the connect() statement is issued both the signal & slot objects must be set to the instances to be connected, that's what connect() does. Changing either of the objects later to an instance has no effect on the earlier connect().

  • 0 Votes
    8 Posts
    2k Views
    JoeCFDJ

    @Gianluca-Bernardi I have default as well. Not sure how you got full before. Good to know you solved the issue.