Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: send signal from QCombobox

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default send signal from QCombobox

    QT:4.1.1

    Hi everybody!
    I am trying to call a function from my combobox but i was not able. I tryied: all signals but it not works.
    It would be perfect if i click on my combobox and send a signal, or call my function...
    Have somebody a idea how could i call my function by clicking my combobox for example.

    My Combobox is per default empty. And my idea is that when you click the combobox a query will started and values should be added to this combobox

    I tried this:
    Qt Code:
    1. connect(ui.sprache_cb, SIGNAL( activated()), this, SLOT(selectSprache()));
    2. connect(ui.sprache_cb, SIGNAL( clicked()), this, SLOT(selectSprache()));
    3. connect(ui.sprache_cb, SIGNAL( highlighted()), this, SLOT(selectSprache()));
    To copy to clipboard, switch view to plain text mode 
    Have i a chance to solve it?
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Run the app from the command prompt and see if you get any warnings.

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Quote Originally Posted by raphaelf
    QT:4.1.1

    Hi everybody!
    I am trying to call a function from my combobox but i was not able. I tryied: all signals but it not works.
    It would be perfect if i click on my combobox and send a signal, or call my function...
    Have somebody a idea how could i call my function by clicking my combobox for example.

    My Combobox is per default empty. And my idea is that when you click the combobox a query will started and values should be added to this combobox

    I tried this:
    Qt Code:
    1. connect(ui.sprache_cb, SIGNAL( activated()), this, SLOT(selectSprache()));
    2. connect(ui.sprache_cb, SIGNAL( clicked()), this, SLOT(selectSprache()));
    3. connect(ui.sprache_cb, SIGNAL( highlighted()), this, SLOT(selectSprache()));
    To copy to clipboard, switch view to plain text mode 
    Have i a chance to solve it?

    So presumably, you start with an empty combobox and you want to react to when the mouse is clicked on it and the combo "drops down"?

    or did I misunderstand?
    Last edited by Chicken Blood Machine; 28th February 2006 at 03:03.
    Save yourself some pain. Learn C++ before learning Qt.

  4. #4
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi Chicken Blood!

    Yes the combobox should be empty at the beginning..(After the first query started the combobox will not be empty)
    And allways when i click my combobox i should see the newest values from the database.
    I dont now wich signal exactly i should use, i just must be shure that on click or activated the combobox, a query should be startet to be sure that the combobox contains the newest values and should be able to choose one of them..
    Think DigitalGasoline

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Just idea...use event filter for catch event QEvent::Show for object yourCmb->listBox()
    a life without programming is like an empty bottle

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: send signal from QCombobox

    activated and highlighted signals are emitted only when combo box contains items than can be activated or highlighted.

    Try this:
    Inherit QComboBox and override:
    Qt Code:
    1. void QWidget::focusInEvent ( QFocusEvent * event ) [virtual protected]
    To copy to clipboard, switch view to plain text mode 
    When the combo box receives focus for the first time (when it's empty), you could emit a signal stating it needs to be populated.

  7. #7
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi everybody,

    Zlatko and Jpn, the both idea are nice..
    Where could i find examples?I need more Information how to implement it..
    Thanx
    Think DigitalGasoline

  8. #8
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Do try to create the successor from the QComboBox class. Such as:
    Qt Code:
    1. class ComboBoxModify : public QComboBox
    2. {
    3. Q_OBJECT
    4. public:
    5. ComboBoxModify(QWidget * pParent = 0)
    6. : QComboBox(pParent) { ; };
    7. public slots:
    8. void setCurrentIndex ( int index )
    9. {
    10. QComboBox::setCurrentIndex( index );
    11. emit QComboBox::activated ( index );
    12. };
    13. };
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Qt Code:
    1. // in header of your form
    2. protected:
    3. bool eventFilter( QObject *o, QEvent *e );
    4.  
    5. // in constructor your form
    6. installEventFilter(yourCmb->listBox());
    7.  
    8. // then
    9. bool yourForm::eventFilter( QObject *o, QEvent *e )
    10. {
    11. if ( e->type() == QEvent::Show )
    12. {
    13. yourMethod();
    14. return TRUE; // eat event
    15. } else
    16. {
    17. // standard event processing
    18. return FALSE;
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

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

    raphaelf (28th February 2006)

  11. #10
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi Zlatko,

    Thanks for your fast Support!
    I get a error Message:
    Qt Code:
    1. test.cpp:16: error: 'class QComboBox' has no member named 'listBox'
    To copy to clipboard, switch view to plain text mode 

    Could be that you mean another member?I think listbox was in Qt3 possible..


    MAD MAX: Thanks for your example too, i have see just now(you reply in 120 seconds)..I will try all sendet examples
    Last edited by raphaelf; 28th February 2006 at 11:15.
    Think DigitalGasoline

  12. #11
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Yes qt4 hasnt..i think you must use comboboxes method view()
    a life without programming is like an empty bottle

  13. #12
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi,

    I get No Errors now...But if i click my ComboBox my Function "selectSprache()" will not be called, Can somebody see why?

    Qt Code:
    1. #include "test.h"
    2.  
    3. #include <QMessageBox>
    4. #include <QSqlDatabase>
    5. #include <QSqlQuery>
    6. #include <QSqlError>
    7. #include <QTextEdit>
    8. #include <QStatusBar>
    9. #include <QAbstractItemView>
    10. #include <QEvent>
    11.  
    12.  
    13.  
    14.  
    15. MainWindow::MainWindow()
    16.  
    17. {
    18. ui.setupUi(this);
    19. installEventFilter(ui.sprache_cb->view());
    20.  
    21. connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(verbinden()));
    22. connect(ui.speichern_btn, SIGNAL(clicked()), this, SLOT(selectSprache()));
    23. }
    24.  
    25. bool MainWindow::verbinden()
    26. {
    27. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    28. db.setHostName("pcpsr5");
    29. db.setDatabaseName("DRIVER={SQL Server};SERVER=pcpsr5;DATABASE=inventar;UID=sa;PWD=");
    30. db.setUserName("sa");
    31. db.setPassword("");
    32. if(!db.open())
    33. {
    34. QMessageBox::information(this,"",db.lastError().text());
    35. return false;
    36. }
    37. else
    38. return true;
    39. }
    40. void MainWindow::selectSprache()
    41. {
    42. /*
    43. QSqlQuery select (" select sprache from sprache_tbl");
    44. while(select.next())
    45. {
    46. QString sprachen = select.value(0).toString();
    47. ui.sprache_te->insertPlainText(sprachen + " ");
    48. }
    49. */
    50. QMessageBox::information(this,"","");
    51. }
    52.  
    53. bool MainWindow::eventFilter( QObject *o, QEvent *e )
    54. {
    55. if ( e->type() == QEvent::Show )
    56. {
    57. selectSprache();
    58. return TRUE;
    59. }
    60. else
    61. return FALSE;
    62.  
    63. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "ui_mainwindow.h"
    2.  
    3.  
    4.  
    5. class MainWindow : public QMainWindow
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. MainWindow();
    11. QStatusBar *statusbar;
    12.  
    13.  
    14. public slots:
    15. bool verbinden();
    16. void selectSprache();
    17.  
    18.  
    19. private:
    20. Ui::MainWindow ui;
    21.  
    22. protected:
    23. bool eventFilter( QObject *o, QEvent *e );
    24.  
    25.  
    26.  
    27. };
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  14. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: send signal from QCombobox

    The way event filters are used is:
    monitoredObj->installEventFilter(filterObj)

    so in your case it would be:
    ui.sprache_cb->installEventFilter(this)

    If you want to populate your combo box due to a click, you might wanna consider changing QEvent::Show to some other event. Combo box receives the show event during the startup of the application..

  15. #14
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Stop...its bad idea catch this event if listview is empty .
    Has your combo is editable?
    If no try use event filter for object combobox and something event alikeQEvent::MouseButtonPress

    sorry for my thoughtlessness
    a life without programming is like an empty bottle

  16. #15
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    Quote Originally Posted by jpn
    The way event filters are used is:
    monitoredObj->installEventFilter(filterObj)

    so in your case it would be:
    ui.sprache_cb->installEventFilter(this)

    If you want to populate your combo box due to a click, you might wanna consider changing QEvent::Show to some other event. Combo box receives the show event during the startup of the application..
    he try catch Event::Show from comboboxes listview
    a life without programming is like an empty bottle

  17. #16
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: send signal from QCombobox

    Quote Originally Posted by zlatko
    he try catch Event::Show from comboboxes listview
    Ok, then there is a problem that the list never gets shown as it's empty..

    Edit: as you seem to have already noticed Nevermind...

  18. #17
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi Guys..
    like that it works, but just if i dobleclick my combobox
    Qt Code:
    1. #include "test.h"
    2.  
    3. #include <QMessageBox>
    4. #include <QSqlDatabase>
    5. #include <QSqlQuery>
    6. #include <QSqlError>
    7. #include <QTextEdit>
    8. #include <QStatusBar>
    9. #include <QAbstractItemView>
    10. #include <QEvent>
    11.  
    12.  
    13.  
    14.  
    15. MainWindow::MainWindow()
    16.  
    17. {
    18. ui.setupUi(this);
    19. ui.sprache_cb->installEventFilter(this);
    20.  
    21.  
    22. connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(verbinden()));
    23.  
    24.  
    25. }
    26.  
    27. bool MainWindow::verbinden()
    28. {
    29. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    30. db.setHostName("pcpsr5");
    31. db.setDatabaseName("DRIVER={SQL Server};SERVER=pcpsr5;DATABASE=inventar;UID=sa;PWD=");
    32. db.setUserName("sa");
    33. db.setPassword("");
    34. if(!db.open())
    35. {
    36. QMessageBox::information(this,"",db.lastError().text());
    37. return false;
    38. }
    39. else
    40. return true;
    41. }
    42. void MainWindow::selectSprache()
    43. {
    44. ui.sprache_cb->clear();
    45. ui.sprache_cb->insertItem(0,"");
    46. QSqlQuery select (" select sprache from sprache_tbl");
    47. while(select.next())
    48. {
    49. QString sprachen = select.value(0).toString();
    50. ui.sprache_cb->insertItem(1, sprachen);
    51. }
    52.  
    53. }
    54.  
    55. bool MainWindow::eventFilter( QObject *o, QEvent *e )
    56. {
    57. if ( e->type() == QEvent::MouseButtonPress )
    58. {
    59. selectSprache();
    60. return TRUE;
    61. }
    62. else
    63. return FALSE;
    64.  
    65. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  19. #18
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: send signal from QCombobox

    try release event use
    a life without programming is like an empty bottle

  20. #19
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi!
    I get new values just if i click twice..and on release the small button right from the combobox stay active (like a toogle button) until a click again ;(
    Qt Code:
    1. QEvent::MouseButtonRelease
    To copy to clipboard, switch view to plain text mode 

    May be its not the right way to send a Signal from the ComboBox..
    Think DigitalGasoline

  21. #20
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: send signal from QCombobox

    Hi,
    "QEvent::FocusIn" looks to work but i have a symptom..if i ordered my query the results are interchanged
    combo: x,f,a
    Query Analyzer: a,f,x

    "select sprache from sprache_tbl order by sprache"
    Think DigitalGasoline

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  3. QComboBox activated signal: bad int value?
    By rfdutt in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2008, 00:29
  4. Can you send a signal to a thread?
    By Dumbledore in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 21:31
  5. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.