Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Updating QLineEdit Text Causing Crash

$
0
0
Hi, Qt beginner here…I’m using Qt Creator 2.8.1 with Qt 5.1.1 on Ubuntu 12.04. Part of the app I’m writing is a file uploader and I’m trying to create a slot so that when the user selects a file, the QLineEdit is updated to reflect the file name. Here’s my code: topcash.cpp #include "topcash.h"   Topcash::Topcash(){     createUploadArea();     createQuoteArea();     createFinalArea();       QVBoxLayout *mainLayout = new QVBoxLayout;     mainLayout->addWidget(uploadLayout);     mainLayout->addWidget(quoteLayout);     mainLayout->addWidget(finalLayout);     setLayout(mainLayout); }   void Topcash::createUploadArea(){     uploadLayout = new QGroupBox(tr("1) Select file to upload"));     QVBoxLayout *layout = new QVBoxLayout;       QGroupBox *upload_horiz = new QGroupBox();     QHBoxLayout *upload_layout = new QHBoxLayout;     upload_layout->setAlignment(Qt::AlignLeft);       QLineEdit *upload_box = new QLineEdit;     upload_box->setMinimumWidth(400);     upload_box->setMaximumWidth(400);     upload_box->setReadOnly(true);     upload_box->setStyleSheet("background-color:#D8D8D8;border:1px solid #B0B0B0;border-radius:3px;");       QPushButton *browse_btn = new QPushButton(tr("Browse"));     browse_btn->setMaximumWidth(80);     connect(browse_btn, SIGNAL(clicked()), this, SLOT(open()));       upload_layout->addWidget(upload_box);     upload_layout->addWidget(browse_btn);     upload_horiz->setLayout(upload_layout);       QPushButton *upload_button = new QPushButton(tr("Upload"));     upload_button->setMaximumWidth(80);       layout->addWidget(upload_horiz);     layout->addWidget(upload_button);     uploadLayout->setLayout(layout);   }   void Topcash::createQuoteArea(){     quoteLayout = new QGroupBox(tr("2) Quote List:"));       QVBoxLayout *layout = new QVBoxLayout;     layout->setAlignment(Qt::AlignTop);       QPlainTextEdit *quote_text = new QPlainTextEdit;     quote_text->setReadOnly(true);     quote_text->setMinimumWidth(600);     quote_text->setMaximumWidth(600);     quote_text->setMinimumHeight(300);     quote_text->setMaximumHeight(300);       layout->addWidget(quote_text);     quoteLayout->setLayout(layout); }   void Topcash::createFinalArea(){     finalLayout = new QGroupBox(tr("3) Choose Action:"));       QHBoxLayout *layout = new QHBoxLayout;     layout->setAlignment(Qt::AlignLeft);       QPushButton *export_csv = new QPushButton(tr("Export as CSV"));     export_csv->setMaximumWidth(298);     export_csv->setMinimumWidth(298);       QPushButton *email_list = new QPushButton(tr("Email List"));     email_list->setMaximumWidth(298);     email_list->setMinimumWidth(298);       layout->addWidget(export_csv);     layout->addWidget(email_list);       finalLayout->setLayout(layout); }     void Topcash::open(){     QString file_name = QFileDialog::getOpenFileName(this);     if (!file_name.isEmpty()){         loadFile(file_name);     } }   void Topcash::loadFile(const QString &file_name){     upload_box->setText("WHY IS THIS CRASHING!?!");   } topcash.h #ifndef WIDGET_H #define WIDGET_H   #include <QWidget> #include <QLabel> #include <QPushButton> #include <QVBoxLayout> #include <QGroupBox> #include <QPushButton> #include <QHBoxLayout> #include <QLineEdit> #include <QPlainTextEdit> #include <QFileDialog>   class Topcash : public QWidget{     Q_OBJECT   public:     Topcash();   private slots:     void open();   private:     QGroupBox *uploadLayout, *finalLayout, *quoteLayout;     QPushButton *upload_button, *browse_btn, *export_csv, *email_list;     QLineEdit *upload_box;     void createUploadArea();     void createQuoteArea();     void createFinalArea();     void loadFile(const QString &file_name); };   #endif // WIDGET_H For some reason that I can’t figure out, the app crashes when loadFile is called. Any ideas? Thanks!

Viewing all articles
Browse latest Browse all 13965

Trending Articles