Results 1 to 11 of 11

Thread: customslots in qt4

  1. #1
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default customslots in qt4

    Hello designers

    I am using qt4 ( windows)

    Howdoes one add custom slot .
    And where to write the code for that custom slot function as we used to do in qt3.
    By the way is there qt3 version for windows ( integrated type) as we have for Unix/Linux.
    and if it is there where to get it .

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    Quote Originally Posted by deekayt View Post
    Howdoes one add custom slot .
    And where to write the code for that custom slot function as we used to do in qt3.
    In Qt3 there were two ways: hackish .ui.h files and elegant subclassing approach. In Qt4 only the latter is available, so you can't edit code in Qt Designer (since it's a designer, not IDE) and you can't add custom slots to .ui files.

    Read this: http://doc.trolltech.com/4.2/designe...component.html (especially the "The Single Inheritance Approach" section).


    Quote Originally Posted by deekayt View Post
    By the way is there qt3 version for windows ( integrated type) as we have for Unix/Linux.
    I'm not sure what you are asking for.

  3. #3
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    Hmm...
    I have gone through other threads of porting from qt3.3.4(Linux)to qt 4(windows) in which you have extensively supported.
    I shall try to port the code.
    But just a little bit of doubt.
    The custom slots which I added in qt3.3.4(linux) was through this hckish.ui.h approach and not by subclassing.( infact the quickstart help of qt3.3.4 ( linux ) gives the example of that "metric conversion" using this hckish.ui.h approach to add custom slots)
    NOw when I port the code will it be ok.

    please advise
    thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    Quote Originally Posted by deekayt View Post
    infact the quickstart help of qt3.3.4 ( linux ) gives the example of that "metric conversion" using this hckish.ui.h approach to add custom slots
    I guess they did that just not to scare away newbies, that are afraid of adding few extra lines of code, even if it would grant them more flexibility in the future.

    Actually there is no point in adding custom slots to the .ui file, since your application won't use the code generated from it directly. What it will use is the class you are going to write and that class can have any slots and signals you want and any constructor you want. You can even derive it from some custom base class. This approach gives you full control over your source on the contrary to the .ui.h files.

  5. #5
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    ok fine let me first try and port
    any problems faced i will come back with the error messages.
    bye

  6. #6
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    • I have gone through the document “Qt 4_2 Using a Component in Your Application”and have been able to run the direct approach. However whatever I try for the The Single Inheritance Approach , The Multiple Inheritance Approach and Automatic Connections , Without and with Auto-Connect the code is not coming right .
    • In case of direct approach I just make a dialog with say buttons on the right , put it in a folder with main.cpp file ( as given below) and run qmake and make. The thing works .
    #include "ui_imagedialog.h"
    #include <QApplication>
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QDialog *window = new QDialog;
    Ui::ImageDialog ui;
    ui.setupUi(window);

    window->show();
    return app.exec();
    }
    Now when I want to adopt the other approaches where should I put the codes

    class ImageDialog : public QDialog
    {
    Q_OBJECT

    public:
    ImageDialog(QWidget *parent = 0);

    private:
    Ui::ImageDialog ui;
    };
    Should it be put in main above the int main() function.
    And what should I now have in main() function.

    And for the code given below should I have some other header file.
    ImageDialog::ImageDialog(QWidget *parent)
    : QDialog(parent)
    {
    ui.setupUi(this);

    ui.colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)"));
    ui.colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)"));

    connect(ui.okButton, SIGNAL(clicked()), this, SLOT(accept()));
    connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    }
    I have triad all combinations but I am not getting it right in any of the approaches

    Please please guide me
    I shall be very grateful

    deekayt

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    Quote Originally Posted by deekayt View Post
    what should I now have in main() function.
    You main should look more or less like this:
    Qt Code:
    1. #include <QApplication>
    2. #include "imagedialog.h"
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7. ImageDialog dlg;
    8. dlg.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by deekayt View Post
    And for the code given below should I have some other header file.
    In general you put class definitions in header files (*.h) and method implementation in implementation files (*.cpp).

  8. #8
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    You have included "imagedialog.h" is ti the one generated by the uic .Should it not be ui_imagedialog.h. Or is it that the class definition

    class ImageDialog : public QDialog
    {
    Q_OBJECT

    public:
    ImageDialog(QWidget *parent = 0);

    private:
    Ui::ImageDialog ui;
    };
    is the one which will be put in the imagedialog.h or do I make a new header fileand put the above class definition and below thing in that .I will have to include that in the project file also.

    ImageDialog::ImageDialog(QWidget *parent)
    : QDialog(parent)
    {
    ui.setupUi(this);

    ui.colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)"));
    ui.colorDepthCombo->addItem(tr("4 colors (2 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("16 colors (4 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("256 colors (8 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("65536 colors (16 bits per pixel)"));
    ui.colorDepthCombo->addItem(tr("16 million colors (24 bits per pixel)"));

    connect(ui.okButton, SIGNAL(clicked()), this, SLOT(accept()));
    connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
    }
    GUide me please

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    Quote Originally Posted by deekayt View Post
    You have included "imagedialog.h" is ti the one generated by the uic .Should it not be ui_imagedialog.h.
    No, ui_imagedialog.h is the one where Ui::ImageDialog is defined. imagedialog.h (or whatever you will call it) is a header file with ImageDialog definition.

    Take a look at QTDIR/examples/designer/calculatorform.

    Quote Originally Posted by deekayt View Post
    GUide me please
    Actually these are complete C++ basics, that you should know before even thinking about using Qt.

  10. The following user says thank you to jacek for this useful post:

    deekayt (20th October 2006)

  11. #10
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4

    THANK YOU VERY MUCH
    I WAS ABLE TO RUN THE APPLICATION ATLAST ....

    I need to first start some processes fromthe mother application ( dialog) on the clickof the pushbutton. I tried the Q process but it didnot work out.Then I resorted to System call . This I know is not a clean process but just to check the slot thing I have put this now.

    my code snippet is as
    steg::steg(QWidget *parent)
    : QDialog(parent)
    {
    ui.setupUi(this);
    connect(ui.okButton, SIGNAL(clicked()), this, SLOT(test()));
    connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(open_file()));
    }

    void steg::test()
    {
    system("e:\"\"\"stego.jpg");
    }
    you see above the okbutton on being clicked gives signal to slot test() .test() function has system call to launch picture viewer to show the file stego.jpg.
    Canyou suggest a better method to do this task.

    Secondly I need to create , open , write , execute and close the file very often in my program on the click of buttons.

    i tried the following snippets

    void steg::writeinfile()
    {
    char eog_comand[]= "eog";
    char space[]= " ";
    FILE *fp;
    fp = fopen ("e:\"\"\"trial.txt", "w+");
    fputs (eog_comand,fp);
    fputs (space,fp);
    fclose(fp);
    }
    this is simple c code .But when i run the program it crashes.
    I tried Qfile commands
    void steg::writeinfile()
    {
    QFile file;
    file.setFileName("e:\"\"\"trial.txt");
    file.open(QIODevice::WriteOnly);
    file.write(msg, qstrlen(msg)); // write to stderr
    file.close();
    }
    But that alsodoesnot work
    Someguidance please.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: customslots in qt4


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.