Results 1 to 9 of 9

Thread: Need help with button !

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Need help with button !

    Hi everyone,

    after get a lots of help from expert im still stuck with my button..

    i have 2 "design" page (form.ui) "Qdialog"

    mainwindow.ui

    and

    dialog.ui


    i have one button on mainwindow.ui and i want to click that button to go to dialog.ui..

    i design only with the designer thing with a double click on mainwindow.ui or dialog.ui

    can someone please write me that simple step for me ?? i really can't figure out how and where to write codes - -" ... as you will see i put some script already (from the help i had in my last post) the debug mode works fine but when i press the button my program crash ?!!

    i guess something wrong with my code still or im not doing the step right..

    thank you very much

    Max




    here are the code from each pages:

    Dialog.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <widget class="QCalendarWidget" name="calendarWidget">
    <property name="geometry">
    <rect>
    <x>80</x>
    <y>40</y>
    <width>256</width>
    <height>155</height>
    </rect>
    </property>
    </widget>
    </widget>
    <resources/>
    <connections/>
    </ui>


    mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>360</width>
    <height>640</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>120</x>
    <y>180</y>
    <width>121</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>PushButton</string>
    </property>
    </widget>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>

    dialog.h

    #ifndef DIALOG_H
    #define DIALOG_H

    #include <QDialog>

    namespace Ui {
    class Dialog;
    }

    class Dialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    private:
    Ui::Dialog *ui;
    };

    #endif // DIALOG_H

    mainwindow.h


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>
    #include <QDialog>
    #include "dialog.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {

    QDialog *dialog;
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;

    private slots:
    void on_pushButton_clicked();
    };

    #endif // MAINWINDOW_H

    dialog.ccp


    #include "dialog.h"
    #include "ui_dialog.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    }

    Dialog::~Dialog()
    {
    delete ui;
    }

    main.cpp


    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;

    #if defined(Q_WS_S60)
    w.showMaximized();
    #else
    w.showFullScreen();

    #endif
    return a.exec();
    }

    mainwindow.cpp


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "ui_dialog.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked()
    {
    dialog->exec();
    }
    Last edited by wreckx; 22nd November 2010 at 09:03. Reason: reformatted to look better

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Need help with button !

    You have only the pointer there, create an object, using new if you use a pointer, or you can create one dialog on the stack if you use .exec() to make it modal.

    Take a look at this FAQ

    LE: also check the classes names, because you created your own Dialog class and you created a pointer to QDialog class in the mainwindow.

Similar Threads

  1. Changing text of button in no relation to button
    By Sabre Runner in forum Newbie
    Replies: 22
    Last Post: 23rd September 2010, 12:29
  2. Replies: 6
    Last Post: 21st August 2010, 21:09
  3. Replies: 1
    Last Post: 2nd August 2010, 05:40
  4. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 09:03

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
  •  
Qt is a trademark of The Qt Company.