Results 1 to 3 of 3

Thread: Can’t connect the signal to the value of the ProgressBar(would crash)

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Can’t connect the signal to the value of the ProgressBar(would crash)

    .hpp

    Qt Code:
    1. #ifndef PROGRESSCONNECTION_HPP
    2. #define PROGRESSCONNECTION_HPP
    3.  
    4. #include <QObject>
    5.  
    6. class progressConnection : public QObject
    7. {
    8. Q_OBJECT
    9. Q_PROPERTY(int progressMaximum READ progressMaximum WRITE setProgressMaximum NOTIFY progressMaximumChanged)
    10. Q_PROPERTY(int progressValue READ progressValue WRITE setProgressValue NOTIFY progressValueChanged)
    11. public:
    12. explicit progressConnection(QObject *parent = 0);
    13.  
    14. Q_INVOKABLE void addProgressValue();
    15.  
    16. int progressMaximum() const;
    17. int progressValue() const;
    18.  
    19. void setProgressMaximum(int value);
    20. void setProgressValue(int value);
    21.  
    22. signals:
    23. void progressMaximumChanged();
    24. void progressValueChanged();
    25.  
    26. private:
    27. void addProgressValueImpl();
    28.  
    29. private:
    30. QMutex mutex_;
    31.  
    32. int progressMaximum_;
    33. int progressValue_;
    34.  
    35. int size_;
    36. };
    37.  
    38. #endif // PROGRESSCONNECTION_HPP
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include <QDebug>
    2.  
    3. #include "progressConnection.hpp"
    4.  
    5. progressConnection::progressConnection(QObject *parent) :
    6. QObject(parent),
    7. progressMaximum_(1),
    8. progressValue_(0),
    9. size_(100000)
    10. {
    11. }
    12.  
    13. void progressConnection::addProgressValue()
    14. {
    15. setProgressMaximum(size_);
    16. setProgressValue(0);
    17.  
    18. addProgressValueImpl();
    19. }
    20.  
    21. int progressConnection::progressMaximum() const
    22. {
    23. return progressMaximum_;
    24. }
    25.  
    26. int progressConnection::progressValue() const
    27. {
    28. return progressValue_;
    29. }
    30.  
    31. void progressConnection::setProgressMaximum(int value)
    32. {
    33. if(value != progressMaximum_){
    34. progressMaximum_ = value;
    35. qDebug()<<"progress maximum = "<<progressMaximum_;
    36. emit progressMaximumChanged();
    37. }
    38. }
    39.  
    40. void progressConnection::setProgressValue(int value)
    41. {
    42. if(value != progressValue_){
    43. progressValue_ = value;
    44. //qDebug()<<"progress value = "<<progressValue_;
    45. emit progressValueChanged();
    46. }
    47. }
    48.  
    49. void progressConnection::addProgressValueImpl()
    50. {
    51. for(int i = 0; i != size_; ++i){
    52. setProgressValue(i);
    53. }
    54. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <QQmlEngine>
    3. #include <QQuickView>
    4. #include <QtQml>
    5.  
    6. #include "progressConnection.hpp"
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11.  
    12. qmlRegisterType<progressConnection>("Test", 1, 0, "ProgressConnection");
    13.  
    14. QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
    15. QObject *topLevel = engine.rootObjects().value(0);
    16. QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    17. if (!window) {
    18. qWarning("Error: Your root item has to be a Window.");
    19. return -1;
    20. }
    21. window->show();
    22.  
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    main.qml
    Qt Code:
    1. import QtQuick 2.1
    2. import QtQuick.Controls 1.0
    3. import QtQuick.Dialogs 1.0
    4. import QtQuick.Layouts 1.0
    5.  
    6. import Test 1.0
    7.  
    8. ApplicationWindow{
    9. id: root
    10.  
    11. title: "Color Correction"
    12.  
    13. color: syspal.window
    14. width: 1450
    15. height: 750
    16. minimumHeight: 750
    17. minimumWidth: 1400
    18.  
    19. SystemPalette {id: syspal}
    20.  
    21. Component{
    22. id: compProgressTest
    23.  
    24. ProgressConnection{
    25.  
    26. }
    27. }
    28.  
    29. Loader{
    30. id: loader
    31.  
    32. sourceComponent: null
    33.  
    34. onStatusChanged: {
    35. if(loader.status == Loader.Ready){
    36. console.log("Ready")
    37. }
    38. }
    39. }
    40.  
    41. Row{
    42. anchors.fill: parent
    43.  
    44. Button{
    45. text: "reload"
    46. onClicked: {
    47. loader.sourceComponent = null
    48. loader.sourceComponent = compProgressTest
    49. }
    50. }
    51.  
    52. Button{
    53. text: "run"
    54. onClicked: {
    55. if(loader.status == Loader.Ready){
    56. loader.item.addProgressValue()
    57. }
    58. }
    59. }
    60.  
    61. ProgressBar{
    62. id: progressBar
    63.  
    64. maximumValue: loader.status == Loader.Ready ? loader.item.progressMaximum : 1
    65. value: loader.status == Loader.Ready ? loader.item.progressValue : 0
    66.  
    67. onValueChanged: {
    68. console.log("progress bar value = " + progressBar.value)
    69. }
    70. }
    71. }
    72.  
    73. }
    To copy to clipboard, switch view to plain text mode 

    The codes would crash, have no idea what kind of mistakes I do

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can’t connect the signal to the value of the ProgressBar(would crash)

    Try something simpler first, e.g. just an ApplicationWindow and the custom type, no loader, etc.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can’t connect the signal to the value of the ProgressBar(would crash)

    The other experiment, I Remove all of my Loader codes(but do not make the ProgressBar as context property).

    I don’t know why, after I replace the Loader codes with
    Qt Code:
    1. ProgressConnection{
    2. id: progressConnection
    3. }
    To copy to clipboard, switch view to plain text mode 
    The program wouldn’t crash again weather it is single thread or multi-thread, pretty weird
    Do the loader of Qt5.1 has some bugs?Or my mistakes?

Similar Threads

  1. Crash on connect
    By trust88 in forum Qt Programming
    Replies: 2
    Last Post: 3rd May 2013, 17:44
  2. How to connect signal to signal in QWidget correctly
    By Mint87 in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2013, 00:06
  3. Connect signal/signal in Qt Designer
    By jlemaitre in forum Newbie
    Replies: 1
    Last Post: 22nd September 2010, 15:53
  4. crash at connect
    By Arifa in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2010, 12:09
  5. Emitting signal causes CRASH
    By navi1084 in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2009, 16:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.