Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]myWindow.exe exited with code -1073741819
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]myWindow.exe exited with code -1073741819

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi all,
    I am trying to use a QListwidget so that when I click on it ,the text in the items changes accordingly.The header code is as follows
    @#include <QWidget>
    #include <QListWidget>
    #include <QPushButton>
    #include <QVBoxLayout>
    class MyWindow:public QWidget
    {
    Q_OBJECT
    public:
    MyWindow();

    public slots:
    void processItems();

    private:
    QListWidget *mWdgt;
    };
    @

    and the implementation code is as follows:
    @MyWindow::MyWindow()
    {

    QListWidget *mWdgt=new QListWidget(this);
    mWdgt->addItem("inka");
    mWdgt->addItem("intama");
    mWdgt->addItem("ihene");
    mWdgt->addItem("inka");

    QPushButton *button1=new QPushButton("Click Me",this);
    QVBoxLayout *myVLayout=new QVBoxLayout;
    myVLayout->addWidget(mWdgt);
    myVLayout->addWidget(button1);

    setLayout(myVLayout);

    QObject::connect(button1, SIGNAL(clicked()),
    this,SLOT(processItems()));

    }

    void MyWindow::processItems()
    {
    mWdgt->currentItem()->setText("amahoro");

    }@

    The code compiles nice but when i run it he following message pops up after a windows error message."exe exited with code -1073741819"
    Any help would be appreciated since this has been bugging me for some time.When I start from the Gui project
    it works.I just want to be able to do it from raw code.

    Thanks.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      mWdgt you create in the constructor (line 4) is a local variable, in no way connected to private mWdgt declared in the header and modified in the ::processItems() slot.

      Add this to your constructor. I suggest rethinking the rest of the design a bit, too.
      @
      this->mWdgt = mWdgt;
      @

      Just to be clear: the reason your app crashes is that currently the mWdgt pointer in the processItems() is a dangling pointer (not initialised).

      (Z(:^

      1 Reply Last reply
      0
      • musimbateM Offline
        musimbateM Offline
        musimbate
        wrote on last edited by
        #3

        Thanks sierdzio ,I did as you said and it worked.I am learning c++ and exploring the concepts of classes using Qt.Thanks again!

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Sure thing, have fun and ask more if something is not clear :)

          (Z(:^

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved