×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    12

    What is wrong with this simple application..

    Hi, anyone can help me and tell me what is wrong with my widget application? It compiles just fine but SettingsDialog never pops up when clicking the button. Obviously there is something I don't understand here.

    main.cpp
    Code:
    #include "qmaemo5homescreenadaptor.h"
    #include "testwidget.h"
    #include "settingsdialog.h"
    #include <QtGui>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        TestWidget w;
        QMaemo5HomescreenAdaptor *a = new QMaemo5HomescreenAdaptor(&w);
        a->setSettingsAvailable(true);
        QObject::connect(a, SIGNAL(settingsRequested()), &w, SLOT(showSettingsDialog()));
        w.show();
        app.exec();
    }
    testwidget.h
    Code:
    #ifndef TESTWIDGET_H
    #define TESTWIDGET_H
    
    #include <QtGui>
    
    class TestWidget : public QLabel
    {
        Q_OBJECT
    public:
        TestWidget();
    public slots:
        void showSettingsDialog();
    };
    
    #endif
    testwidget.cpp
    Code:
    #include "testwidget.h"
    #include "settingsdialog.h"
    
    #include <QtGui>
    
    TestWidget::TestWidget() : QLabel()
    {
        setText("Testing only");
    }
    
    void TestWidget::showSettingsDialog()
    {
        SettingsDialog settingsWindow;
        settingsWindow.show();
    }
    settingsdialog.h
    Code:
    #ifndef SETTINGSDIALOG_H
    #define SETTINGSDIALOG_H
    
    #include <QtGui>
    
    class SettingsDialog : public QDialog
    {
        Q_OBJECT
    public:
        SettingsDialog();
    private:
        QLabel *label;
        QLineEdit *lineEdit;
    };
    
    #endif
    settingsdialog.cpp
    Code:
    #include "settingsdialog.h"
    
    #include <QtGui>
    
    SettingsDialog::SettingsDialog() : QDialog()
    {
        label = new QLabel(tr("Example:"));
        lineEdit = new QLineEdit;
        label->setBuddy(lineEdit);
    
        QHBoxLayout *hLayout = new QHBoxLayout;
        hLayout->addWidget(label);
        hLayout->addWidget(lineEdit);
    
        setLayout(hLayout);
        setWindowTitle(tr("Settings"));
    }
    Thanks in advance!

  2. #2
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: What is wrong with this simple application..

    You create SettingsDialog on the stack and it gets destroyed as soon as showSettingsDialog() quits.

Similar Threads

  1. raccoon-0.9.2: month wrong in /logs application
    By _marv_ in forum Mobile Web Server
    Replies: 11
    Last Post: 2007-06-28, 10:00
  2. Wrong time is displying on mobile application
    By premlathiya in forum Mobile Java General
    Replies: 2
    Last Post: 2007-02-26, 21:29
  3. Simple HTTPS Request Gone Wrong
    By roryfynn in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2006-01-30, 10:15
  4. Replies: 1
    Last Post: 2005-04-06, 15:45
  5. What's going wrong with installation simple midlet (6310i)
    By zgibniew in forum Mobile Java General
    Replies: 3
    Last Post: 2003-09-24, 10:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×