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

    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 

  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

    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 

  3. #3
    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?

  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

    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!

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

    Default Re: Problem with slot

    I am only showing you this, to explain to you that the polygons I am drawing are based on large data sets that must be imported and stored. I originally tried to explain that the process() function brings in all of this data, stores the data using QPolygonF, adds the polygon as a QPainterPath, and adds the path as a QGraphicsPathItem. I then explained that all the items I need to scale were stored and created under the process() function, and if you are now telling I essentially need to re-input the data in the same data structures and essentially copy all the code from process() into processRight(), then I believe there was a misunderstanding along the way. This was something that I was initially trying to avoid. But if you are telling me that this is the only solution, then okay.
    Last edited by mistertoony; 26th March 2007 at 19:00.

  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 originally tried to explain that the process() function brings in all of this data and draws the polygons. I then explained the items I need to scale were stored and created under the process() function,
    At least I understood it defferently.
    Your original problem was getting the signal/slots to work.
    I didn't pay any attention to what you were trying to do IN your code, I was just trying to help you get your code to work, and to explain to you the syntax rules for connecting signal and slot.
    and if you are now telling I essentially need to re-input the data in the same data structures and essentially copy all the code from process() into processRight().
    I never said anything about that.
    If at all then this (more than once):
    You don't need to create new slots, make one slot that connects to the valueChangedRight(int) signal,
    This is true, provided you can do all the work in one slot, that reacts to hte valueChangedRight(int) signal.
    So basically you can do the following:
    Qt Code:
    1. test1::test1() {
    2. setupUi(this);
    3. //connect(pushButton, SIGNAL(clicked()), this, SLOT(process()));
    4. connect(horizontalSlider, SIGNAL(valueChangedRight(int)), this, SLOT(process(int)));
    5. }
    6.  
    7. void test1::process(int pos) {
    8. //adjust your original process() code so that it will remember the last pos,
    9. //and check based on current pos values if the movement is to the left or right.
    10. {
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th March 2007 at 19:58. Reason: wrapped too long line

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

    Default Re: Problem with slot

    I originally used the the following connect function to display the plots with a given standard scale:

    Qt Code:
    1. connect(pushButton, SIGNAL(clicked()), this, SLOT(process()));
    To copy to clipboard, switch view to plain text mode 

    I have revised the code under your recommendation, and the horizontal scale functions correctly. Thank you for this. However, when I first execute the program the graphicsView is empty and the plots only appears once I move the horizontal slider. Under your advise that "provided you can do all the work in one slot," do you have any suggestions to initialize the plot into graphicsView before any changes are made to the horizontal slider.

    Additionally, I am also considering how I would be able to implement the code/logic to configure the connect function:
    Qt Code:
    1. connect(verticalSlider, SIGNAL(valueChanged(int)), this, SLOT(processRight(int)));
    To copy to clipboard, switch view to plain text mode 

    Maybe having one slot will not serve well in my application? Do you agree?
    Last edited by mistertoony; 26th March 2007 at 19:33.

  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

    do you have any suggestions to initialize the plot into graphicsView before any changes are made to the horizontal slider.
    Slots are normal member functions, you can call them any time, not just as a reaction to a signal.
    You could call your slot with the current slider value something like:
    process(slider->value());
    In your initialization function.
    Additionally, I am also considering how I would be able to implement the code/logic to configure the connect function:
    But I showed you already how you can use the current slider position...
    I am not sure what it is you are considering...

    Please note - the code I am suggesting is not a code that you should copy/paste in your code, rather, its only in order to illustrate in code what I mean in words.
    You should adapt it to your code.
    You have to remember I don't know what it is you are trying to do, I don't know your code and what you have done so far, so I can't really give you code that neseceraly will compile for you.
    It might work when the code is short and simple, but don't expect it to be so.
    If you have a design question, then you should explain what is the task you are trying to achieve, what have you done so far, and what the problem is.
    We then can try and give suggestion that might be helpful.

    Generally - when you want your code to react to slider movement, and you want to know in which direction the slider has moved - that was answered here.
    If you still didn't understand it, then ask again, and try to focus in on what it is you still need explained.

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

    Default Re: Problem with slot

    can you refer to me to the class/function references where i you could check which slider sent the current position so that i could accomplish the scaling with one slot.

  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


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

    Default Re: Problem with slot

    high_flyer,

    i have been trying to look at this all weekend and i am having trouble understanding how to implement sender(), i don't even understand how it is used in the examples i found online? would you be able to help me out.

  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

    i have been trying to look at this all weekend and i am having trouble understanding how to implement sender()
    Why would you want to implmenet sender()?
    I don't know what more can I say that the docs are not saying...
    May be if you explain what it is you have trouble understanding I could help you more...
    QObject * QObject::sender () const [protected]

    Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function.

    The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.

    Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.

    See also QSignalMapper.
    Just do something like:
    Qt Code:
    1. if(sender()==someObjPtr)
    2. {
    3. //do something
    4. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Problem with slot

    I just read this thread a few times and I think you might have an incorrect design in your code... Are you creating a new graphics scene each time the slider is used? I don't think you really want it this way, do you? Shouldn't you just scale/move/whatever items on the existing scene?

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.