Results 1 to 20 of 30

Thread: Problem with slot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    Your post is very helpful and has helped me to understand the signals and slots much better. However my problem is that by creating new slots (for example, processRight(int) and processLeft(int)) I do not have access to the items created under the original process() which are required for me to scale. Maybe I have overlooked a point that you have made that allows me to accomplish this?

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

    Default Re: Problem with slot

    Did you read the last part of my post? (may be not, since I edit it)
    You don't need to create new slots, make one slot that connects to the valueChangedRight(int) signal, and use logic code to see if you moved right or left.

  3. #3
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Post Re: Problem with slot

    I hope you are not getting frustrated, but I have difficulty understanding how this works. Based on what I understand I have:

    Qt Code:
    1. public slots:
    2. void process();
    3. void processRight(int);
    To copy to clipboard, switch view to plain text mode 

    and:

    Qt Code:
    1. test1::test1() {
    2. setupUi(this);
    3.  
    4. connect(pushButton, SIGNAL(clicked()), this, SLOT(process()));
    5. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(processRight(int)));
    6. }
    7.  
    8. void test1::processRight(int pos) {
    9. }
    10.  
    11. void test1::process() {
    12. QGraphicsScene *scene = new QGraphicsScene(0,0,samples*10,-115);
    13. QGraphicsPathItem *polyItemA = scene->addPath(pathA, QPen(Qt::green), QBrush(Qt::green, Qt::NoBrush));
    14. graphicsView->setScene(scene);
    15. }
    To copy to clipboard, switch view to plain text mode 

    You are saying that I need to write code in the function processRight(int) to determine whether it increments/decrements? But I still do not understand how I will be able to scale my item, for instance (polyItemA->scale(x,y).

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

    Default Re: Problem with slot

    I hope you are not getting frustrated
    not at all, this forum is for people to ask questions.
    If I would get frustrated I would not answer questions here (and ask some as well)
    You are saying that I need to write code in the function processRight(int)
    No I said:
    You don't need to create new slots, make one slot that connects to the valueChangedRight(int) signal,
    So:
    Qt Code:
    1. //deifne in test1.h:
    2. // m_prevPos; //initialize at start
    3. test1::test1() {
    4. setupUi(this);
    5. connect(pushButton, SIGNAL(clicked()), this, SLOT(process()));
    6. connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(processSlider(int)));
    7. }
    8. void test1::processSlider(int pos) {
    9. if(pos<m_prevPos)
    10. {
    11. //your code for what ever happens when you move left
    12. }
    13. else {
    14. //your code for what ecer happens when you move right
    15. }
    16. m_prevPos = pos;
    17. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    Thanks for the further clarification. The only problem with the code posted above is that the function processSlider:
    Qt Code:
    1. //your code for what ever happens when you move left
    To copy to clipboard, switch view to plain text mode 
    When I move left, the code that I would enter here needs to access an item that I call in process() (polyItemA). How can I access this item from processSlider?

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

    Default Re: Problem with slot

    I don't see the problem...
    Just access it as you would in process()...

  7. #7
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    Quote Originally Posted by high_flyer View Post
    I don't see the problem...
    Just access it as you would in process()...
    error C2065: 'polyItemA' : undeclared identifier

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

    Default Re: Problem with slot

    post your code please

  9. #9
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    Qt Code:
    1. test1::test1() {
    2. setupUi(this);
    3.  
    4. connect(pushButton, SIGNAL(clicked()), this, SLOT(process()));
    5. connect(horizontalSlider, SIGNAL(valueChangedRight(int)), this, SLOT(processRight(int)));
    6. }
    7.  
    8. void test1::processRight(int pos) {
    9. if(pos>prev_pos) {
    10. polyItemA->scale(pos,1);
    11. }
    12. prev_pos = pos;
    13. }
    14.  
    15. void test1::process() {
    16.  
    17. std::string string2 = "test.scf.scf";
    18.  
    19. ReadSFF sff(string2);
    20.  
    21. //int bases = sff.getNum();
    22. //QString Q_bases = QString::number(bases);
    23. //textEdit->append("Number of Bases: " + Q_bases);
    24.  
    25. uint_4 samples = sff.returnNumSamples();
    26. //QString Q_samples = QString::number(samples);
    27. //textEdit->append("Number of Samples: " + Q_samples);
    28.  
    29. uint_2 *sA = new uint_2[samples];
    30. uint_2 *sC = new uint_2[samples];
    31. uint_2 *sG = new uint_2[samples];
    32. uint_2 *sT = new uint_2[samples];
    33. const int size = samples;
    34.  
    35. QPolygonF polygonA;
    36. QPolygonF polygonC;
    37. QPolygonF polygonG;
    38. QPolygonF polygonT;
    39.  
    40. int xScale = 10;
    41. int yScale = 10;
    42.  
    43. for (int i=0; i<size; i++) {
    44. sA[i] = sff.returnSamples_A(i);
    45. sC[i] = sff.returnSamples_C(i);
    46. sG[i] = sff.returnSamples_G(i);
    47. sT[i] = sff.returnSamples_T(i);
    48.  
    49. if ((sA[i]/yScale) > 125) {
    50. polygonA << QPointF(xScale*i,-125);
    51. } else {
    52. polygonA << QPointF(xScale*i,-(sA[i]/yScale));
    53. }
    54.  
    55. if ((sC[i]/yScale) > 125) {
    56. polygonC << QPointF(xScale*i,-125);
    57. } else {
    58. polygonC << QPointF(xScale*i,-(sC[i]/yScale));
    59. }
    60.  
    61. if ((sG[i]/yScale) > 125) {
    62. polygonG << QPointF(xScale*i,-125);
    63. } else {
    64. polygonG << QPointF(xScale*i,-(sG[i]/yScale));
    65. }
    66.  
    67. if ((sT[i]/yScale) > 125) {
    68. polygonT << QPointF(xScale*i,-125);
    69. } else {
    70. polygonT << QPointF(xScale*i,-(sT[i]/yScale));
    71. }
    72. }
    73.  
    74. QGraphicsScene *scene = new QGraphicsScene(0,0,samples*10,-115);
    75.  
    76. QPainterPath segPath;
    77. segPath.lineTo(0,-5);
    78. segPath.closeSubpath();
    79.  
    80. QPainterPath pathA;
    81. QPainterPath pathC;
    82. QPainterPath pathG;
    83. QPainterPath pathT;
    84.  
    85. pathA.addPolygon(polygonA);
    86. pathC.addPolygon(polygonC);
    87. pathG.addPolygon(polygonG);
    88. pathT.addPolygon(polygonT);
    89.  
    90. QGraphicsPathItem *polyItemA = scene->addPath(pathA, QPen(Qt::green), QBrush(Qt::green, Qt::NoBrush));
    91. QGraphicsPathItem *polyItemC = scene->addPath(pathC, QPen(Qt::blue), QBrush(Qt::green, Qt::NoBrush));
    92. QGraphicsPathItem *polyItemG = scene->addPath(pathG, QPen(Qt::black), QBrush(Qt::green, Qt::NoBrush));
    93. QGraphicsPathItem *polyItemT = scene->addPath(pathT, QPen(Qt::red), QBrush(Qt::green, Qt::NoBrush));
    94. // QGraphicsPathItem *segPath1 = scene->addPath(segPath, QPen(Qt::gray), QBrush(Qt::green, Qt::NoBrush));
    95. // QGraphicsPathItem *segPath2 = scene->addPath(segPath, QPen(Qt::gray), QBrush(Qt::green, Qt::NoBrush));
    96.  
    97. polyItemA->setPos(0,0);
    98. polyItemC->setPos(0,0);
    99. polyItemG->setPos(0,0);
    100. polyItemT->setPos(0,0);
    101. // segPath1->setPos(0,-20);
    102. // segPath2->setPos(10,-20);
    103.  
    104. //polyItemA->scale(xSlide,1);
    105.  
    106. graphicsView->setScene(scene);
    107.  
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Problem with slot

    The compiler is right:
    Look at test1::processRight(int pos) :
    You are using polyItemA without defining it first.
    Try:
    Qt Code:
    1. void test1::processRight(int pos) {
    2. if(pos>prev_pos) {
    3. QGraphicsPathItem *polyItemA = scene->addPath(pathA, QPen(Qt::green), QBrush(Qt::green, Qt::NoBrush));
    4. polyItemA->scale(pos,1);
    5. }
    6. prev_pos = pos;
    7. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    After trying your suggestion, I get the error:
    Qt Code:
    1. .\test1.cpp(15) : error C2065: 'pathA' : undeclared identifier
    To copy to clipboard, switch view to plain text mode 

    I am wondering if there is even a way to accomplish this without getting all the data and drawing all the polygons again. Is this the best way to scale using the sliders?

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

    Default Re: Problem with slot

    Well, then define 'pathA'.
    These compiler errors are VERY clear, try thinking on your own a second before you post them here.
    You posted 2 minutes after my post with the new error, which is exactly the same as the one before.
    We help gladly, but try to think the problem on your own first!

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  2. Problem with signals and slots
    By conexion2000 in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2006, 11:20
  3. Replies: 16
    Last Post: 7th March 2006, 16:57
  4. Replies: 7
    Last Post: 15th February 2006, 12:34
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 19:52

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.