Results 1 to 5 of 5

Thread: QMainWIndow not popping up when I run

  1. #1
    Join Date
    Aug 2011
    Posts
    35
    Thanks
    5

    Default QMainWIndow not popping up when I run

    I have created a program which builds and runs without errors but no window pops up when I run. Can someone please tell me why.
    My main function is below:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. struct option long_option[] =
    4. {
    5. {"help", 0, NULL, 'h'},
    6. {"device", 1, NULL, 'D'},
    7. {"rate", 1, NULL, 'r'},
    8. {"channels", 1, NULL, 'c'},
    9. {"frequency", 1, NULL, 'f'},
    10. {"buffer", 1, NULL, 'b'},
    11. {"period", 1, NULL, 'p'},
    12. {"method", 1, NULL, 'm'},
    13. {"format", 1, NULL, 'o'},
    14. {"verbose", 1, NULL, 'v'},
    15. {"noresample", 1, NULL, 'n'},
    16. {"pevent", 1, NULL, 'e'},
    17. {NULL, 0, NULL, 0},
    18. };
    19.  
    20. int err;
    21. snd_pcm_hw_params_t *hwparams;
    22. snd_pcm_sw_params_t *swparams;
    23. int method = 0;
    24. snd_pcm_t *handle;
    25. snd_pcm_channel_area_t *areas;
    26. signed short *samples;
    27. unsigned int chn;
    28.  
    29. snd_pcm_hw_params_alloca(&hwparams);
    30. snd_pcm_sw_params_alloca(&swparams);
    31.  
    32. err = snd_output_stdio_attach(&output, stdout, 0);
    33. if (err < 0) {
    34. printf("Output failed: %s\n", snd_strerror(err));
    35. return 0;
    36. }
    37.  
    38. /* cout<<"Playback device is %s "<<","<< device);
    39.   cout<<"Stream parameters are %iHz, %s, %i channels "<<","<< rate<<","<< snd_pcm_format_name(format), channels;
    40.   cout<<"Sine wave rate is %.4fHz "<<","<< freq;
    41.   cout<<"Using transfer method: %s "<<","<< transfer_methods[method].name;
    42.  */
    43. if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
    44. printf("Playback open error: %s\n", snd_strerror(err));
    45. return 0;
    46. }
    47.  
    48. if ((err = set_hwparams(handle, hwparams, transfer_methods[method].access)) < 0) {
    49. printf("Setting of hwparams failed: %s\n", snd_strerror(err));
    50. exit(EXIT_FAILURE);
    51. }
    52. if ((err = set_swparams(handle, swparams)) < 0) {
    53. printf("Setting of swparams failed: %s\n", snd_strerror(err));
    54. exit(EXIT_FAILURE);
    55. }
    56.  
    57. if (verbose > 0)
    58. snd_pcm_dump(handle, output);
    59.  
    60. samples = new signed short[(period_size * channels * snd_pcm_format_physical_width(format))];
    61.  
    62.  
    63.  
    64. if (samples == NULL) {
    65. printf("Not enough memory\n");
    66. exit(EXIT_FAILURE);
    67. }
    68.  
    69. areas = new snd_pcm_channel_area_t [channels];
    70.  
    71. if (areas == NULL) {
    72. printf("Not enough memory\n");
    73. exit(EXIT_FAILURE);
    74. }
    75. for (chn = 0; chn < channels; chn++) {
    76. areas[chn].addr = samples;
    77. areas[chn].first = chn * snd_pcm_format_physical_width(format);
    78. areas[chn].step = channels * snd_pcm_format_physical_width(format);
    79. }
    80.  
    81.  
    82. err = transfer_methods[method].transfer_loop(handle, samples, areas);
    83. if (err < 0)
    84. printf("Transfer failed: %s\n", snd_strerror(err));
    85.  
    86. delete [] areas;
    87. delete [] samples;
    88. snd_pcm_close(handle);
    89.  
    90.  
    91.  
    92.  
    93.  
    94. QApplication a(argc, argv);
    95. wave w;
    96. w.setWindowTitle("ESG Wave Creator");
    97.  
    98.  
    99. w.show();
    100.  
    101. return a.exec();
    102.  
    103.  
    104. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: QMainWIndow not popping up when I run

    I can't see any windows getting created... unless your own type "wave" is such, but there is no way for anyone to know. If it is a subclassed QMainWindow, most likely its constructor has some kind of a problem.

  3. #3
    Join Date
    Aug 2011
    Posts
    35
    Thanks
    5

    Default Re: QMainWIndow not popping up when I run

    Quote Originally Posted by mvuori View Post
    I can't see any windows getting created... unless your own type "wave" is such, but there is no way for anyone to know. If it is a subclassed QMainWindow, most likely its constructor has some kind of a problem.
    There is a window being created at the bottom of my int main():
    Qt Code:
    1. QApplication a(argc, argv);
    2. wave w;
    3. w.setWindowTitle("ESG Wave Creator");
    4.  
    5. w.show();
    6.  
    7. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    Also, sorry for the lack of information. I used the designer to create the window widget wave.ui. The code above was the main in my main.cpp. wave.cpp and wave.h are below.

    wave.cpp:
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3. #include <qlineedit.h>
    4. #include "ui_wave.h"
    5. #include <QString>
    6. #include <QObject>
    7. #include <QDebug>
    8. #include <stdio.h>
    9. #include <cstdio>
    10. #include <stdlib.h>
    11. #include <cstdlib>
    12. #include <string.h>
    13. #include <cstring>
    14. #include <sched.h>
    15. #include <errno.h>
    16. #include <getopt.h>
    17. #include <alsa/asoundlib.h>
    18. #include <sys/time.h>
    19. #include <sstream>
    20. #include <string>
    21. #include <math.h>
    22. #include <cmath>
    23. #include <iostream>
    24. #include "generate_sine.h"
    25. #include "wave.h"
    26.  
    27. using namespace std;
    28.  
    29.  
    30. static const char *device = "plughw:0,0"; // playback device
    31. static snd_pcm_format_t format = SND_PCM_FORMAT_S16; // sample format- change to 24-bit
    32. static unsigned int rate = 96000; // stream rate
    33. static unsigned int channels = 128; // count of channels
    34. static unsigned int buffer_time = 500000; // ring buffer length in us
    35. static unsigned int period_time = 100000; // period time in us
    36. static double freq; // sinusoidal wave frequency in Hz
    37. static int verbose = 0; // verbose flag
    38. static int resample = 1; // enable alsa-lib resampling
    39. static int period_event = 0; // produce poll event after each period
    40. static snd_pcm_sframes_t buffer_size;
    41. static snd_pcm_sframes_t period_size;
    42. static snd_output_t *output = NULL;
    43. static double ampl;
    44. static double amplitude;
    45. static bool isTrue = true;
    46.  
    47.  
    48. wave::wave(QWidget *parent) :
    49. QMainWindow(parent),
    50. ui(new Ui::wave)
    51. {
    52. ui->setupUi(this);
    53.  
    54.  
    55. /* parent->
    56.   generate_sine(const snd_pcm_channel_area_t *areas,
    57.   snd_pcm_uframes_t offset,
    58.   int count, double *_phase );*/
    59.  
    60.  
    61.  
    62. }
    63. wave::~wave()
    64. {
    65. delete ui;
    66. }
    67.  
    68.  
    69.  
    70. void wave::on_pushButton_clicked()
    71. {
    72. freq = ui->frequency->text().toDouble();
    73. ampl = ui->amplitude->text().toDouble();
    74. snd_pcm_t *handle;
    75. signed short *samples;
    76. snd_pcm_channel_area_t *areas;
    77. double phase = 0;
    78. signed short *ptr;
    79. int err, cptr;
    80.  
    81. while (1) {
    82.  
    83.  
    84. generate_sine(areas, 0, period_size, &phase);
    85. ptr = samples;
    86. cptr = period_size;
    87. while (cptr > 0) {
    88. err = snd_pcm_writei(handle, ptr, cptr);
    89. if (err == -EAGAIN)
    90. continue;
    91. if (err < 0) {
    92. if (xrun_recovery(handle, err) < 0) {
    93. printf("Write error: %s\n", snd_strerror(err));
    94. exit(EXIT_FAILURE);
    95. }
    96. break; /* skip one period */
    97. }
    98. ptr += err * channels;
    99. cptr -= err;
    100. }
    101. }
    102. }
    103.  
    104.  
    105.  
    106. void wave::on_pushButton_2_clicked()
    107. {
    108. isTrue = false;
    109.  
    110. }
    To copy to clipboard, switch view to plain text mode 

    wave.h:
    Qt Code:
    1. #ifndef WAVE_H
    2. #define WAVE_H
    3. #include "ui_wave.h"
    4. #include <alsa/asoundlib.h>
    5. #include <QMainWindow>
    6. #include <QObject>
    7. #include "generate_sine.h"
    8. #include "xrun_recovery.h"
    9.  
    10. namespace Ui {
    11. class wave;
    12. }
    13.  
    14. class wave : public QMainWindow
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit wave(QWidget *parent = 0);
    20. ~wave();
    21.  
    22.  
    23. private slots:
    24. void on_pushButton_clicked();
    25.  
    26. void on_pushButton_2_clicked();
    27. private:
    28. Ui::wave *ui;
    29.  
    30.  
    31.  
    32.  
    33. };
    34.  
    35.  
    36.  
    37. #endif // WAVE_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by duma; 8th August 2011 at 18:09.

  4. #4
    Join Date
    Aug 2011
    Posts
    35
    Thanks
    5

    Default Re: QMainWIndow not popping up when I run

    Quote Originally Posted by mvuori View Post
    I can't see any windows getting created... unless your own type "wave" is such, but there is no way for anyone to know. If it is a subclassed QMainWindow, most likely its constructor has some kind of a problem.
    I created a program in Qt Creator called "wave" which is a QMainWindow.
    As for my problem, I placed the line
    Qt Code:
    1. return a.exec;
    To copy to clipboard, switch view to plain text mode 
    which is the line that executes the application and pops up the window. I placed this line at different parts of the code under in main() to see what line was stopping it from popping up. The window popped up when I placed it in all parts of the code starting from the top, but it stopped at the line:
    Qt Code:
    1. err = transfer_methods[method].transfer_loop(handle, samples, areas);
    2. if (err < 0)
    3. printf("Transfer failed: %s\n", snd_strerror(err));
    To copy to clipboard, switch view to plain text mode 
    This is the line of code that stops my window from popping up. I don't know why. Any help would be greatly appreciated.

  5. #5
    Join Date
    Jul 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMainWIndow not popping up when I run

    I may be way off base, but aren't structs supposed to be declared outside of functions? in a global space?

Similar Threads

  1. Replies: 3
    Last Post: 13th November 2011, 08:12
  2. Replies: 2
    Last Post: 29th June 2011, 15:45
  3. Replies: 0
    Last Post: 17th November 2010, 17:07
  4. QMessageBox not popping up
    By harishankar_b in forum Newbie
    Replies: 0
    Last Post: 13th April 2010, 06:55
  5. Popping up a dialog?
    By brcain in forum Newbie
    Replies: 4
    Last Post: 24th February 2006, 02:54

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.