Re: [Qt-creator] Is there a Try and Catch method in QT

2010-07-01 Thread Nicolas Arnaud-Cormos
On Thursday 01 July 2010 03:01:05 Diego Turcios wrote:
 Hi guys
 I thinks this is the right mailing list for my doubt.
 I am working on a small application in QT. But right now I have the
 following problem.
 I have a line edit, and I want to manipulate the values so only numbers
 (doubles) can be written on this line edit.

The right way to do this in Qt is to use a validator. Just write this line in 
the constructor of your dialog (after setting up the ui).
ui-LEPrecio-setValidator( new QDoubleValidator );

This way you are sure the user can only type a double. No need to do any 
check.

Nicolas

-- 
Nicolas Arnaud-Cormos | nicolas.arnaud-cor...@kdab.com | Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions

___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Is there a Try and Catch method in QT

2010-07-01 Thread Danny Price
Catch them within the handler or in QApplication::notify()

http://strange-paradox.livejournal.com/4902.html

On Thu, Jul 1, 2010 at 2:35 AM, Coda Highland c...@bobandgeorge.com wrote:

 I know this is the wrong mailing list but I will caution that Qt is
 not exception-safe (and doesn't even have to be compiled with
 exception support enabled) and throwing exceptions through Qt code
 (for instance, in a slot or in an event handler) has negative effects.
 It's possible to safely use exceptions (QtConcurrent uses them
 internally for instance) but you need to make sure to catch them
 before it crosses Qt code.

 /s/ Adam

 On Wed, Jun 30, 2010 at 8:05 PM, Carter, Nathan ncar...@bentley.edu
 wrote:
 
  This is actually the Qt-creator mailing list, not the Qt mailing list.
  But
  I'll answer your question anyway.  In the future, though, ask Qt
 questions
  over there.  (It's called qt-interest and shows up if you search for
 that
  term.)
  The QString::toDouble() method does not throw an exception if it gets
 text
  that's not a double.  Instead, it has the ok parameter to let you know
  that information.  See the documentation (inside Qt-creator!) for
  QString::toDouble() to see how to use the ok parameter to do your test,
  instead of try-catch.
  But yes, the very fact that your code compiled tells you that C++ (and
 hence
  Qt) support try-catch structures.
  Nathan
 
 
  On Jun 30, 2010, at 9:01 PM, Diego Turcios wrote:
 
  Hi guys
  I thinks this is the right mailing list for my doubt.
  I am working on a small application in QT. But right now I have the
  following problem.
  I have a line edit, and I want to manipulate the values so only numbers
  (doubles) can be written on this line edit.
  I was trying something like this
 
 
  double quantity;
   try
  {
  quantity=ui-LEPrecio-text().toDouble();
   }
  catch(QString error)
  {
  QMessageBox msgBox;
  msgBox.setText(error);
  msgBox.exec();
  }
  After doing this. I am planning to manipulate the double value, but this
  doesn't work. If I write hello world on the line edit. Supposly it
 converts
  it, and it doesn't work. Any idea ;)
 
  Diego Turcios
  DiegoTc
  Ubuntu User  # 27518
  ---
  Mis Blogs
  http://diegoturcios.wordpress.com/
  https://wiki.ubuntu.com/DiegoTurcios
  --
  Recuerden Dios siempre esta presente:
  http://sagradocorazondejesus-diegotc.blogspot.com/
  ATT1..txt
 
  ___
  Qt-creator mailing list
  Qt-creator@trolltech.com
  http://lists.trolltech.com/mailman/listinfo/qt-creator
 
 

 ___
 Qt-creator mailing list
 Qt-creator@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-creator

___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Is there a Try and Catch method in QT

2010-07-01 Thread thorbjorn.lindeijer
- Original message -
 On Thursday 01 July 2010 03:01:05 Diego Turcios wrote:
  Hi guys
  I thinks this is the right mailing list for my doubt.
  I am working on a small application in QT. But right now I have the
  following problem.
  I have a line edit, and I want to manipulate the values so only
 numbers
  (doubles) can be written on this line edit.
 
 The right way to do this in Qt is to use a validator. Just write this
 line in 
 the constructor of your dialog (after setting up the ui).
 ui-LEPrecio-setValidator( new QDoubleValidator );
 
 This way you are sure the user can only type a double. No need to do
 any 
 check.

Note that Qt also has a QDoubleSpinBox, which is a suitable widget for entering 
double values.

Regards,
Bjorn

___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


[Qt-creator] Is there a Try and Catch method in QT

2010-06-30 Thread Diego Turcios
Hi guys
I thinks this is the right mailing list for my doubt.
I am working on a small application in QT. But right now I have the
following problem.
I have a line edit, and I want to manipulate the values so only numbers
(doubles) can be written on this line edit.
I was trying something like this


double quantity;
 try
{
quantity=ui-LEPrecio-text().toDouble();
 }
catch(QString error)
{
QMessageBox msgBox;
msgBox.setText(error);
msgBox.exec();
}
After doing this. I am planning to manipulate the double value, but this
doesn't work. If I write hello world on the line edit. Supposly it converts
it, and it doesn't work. Any idea ;)

Diego Turcios
DiegoTc
Ubuntu User  # 27518
---
Mis Blogs
http://diegoturcios.wordpress.com/
https://wiki.ubuntu.com/DiegoTurcios
--
Recuerden Dios siempre esta presente:
http://sagradocorazondejesus-diegotc.blogspot.com/
___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Is there a Try and Catch method in QT

2010-06-30 Thread Carter, Nathan

This is actually the Qt-creator mailing list, not the Qt mailing list.  But 
I'll answer your question anyway.  In the future, though, ask Qt questions over 
there.  (It's called qt-interest and shows up if you search for that term.)

The QString::toDouble() method does not throw an exception if it gets text 
that's not a double.  Instead, it has the ok parameter to let you know that 
information.  See the documentation (inside Qt-creator!) for 
QString::toDouble() to see how to use the ok parameter to do your test, instead 
of try-catch.

But yes, the very fact that your code compiled tells you that C++ (and hence 
Qt) support try-catch structures.

Nathan



On Jun 30, 2010, at 9:01 PM, Diego Turcios wrote:

Hi guys
I thinks this is the right mailing list for my doubt.
I am working on a small application in QT. But right now I have the following 
problem.
I have a line edit, and I want to manipulate the values so only numbers 
(doubles) can be written on this line edit.
I was trying something like this


double quantity;
 try
{
quantity=ui-LEPrecio-text().toDouble();
 }
catch(QString error)
{
QMessageBox msgBox;
msgBox.setText(error);
msgBox.exec();
}
After doing this. I am planning to manipulate the double value, but this 
doesn't work. If I write hello world on the line edit. Supposly it converts it, 
and it doesn't work. Any idea ;)
Diego Turcios
DiegoTc
Ubuntu User  # 27518
---
Mis Blogs
http://diegoturcios.wordpress.com/
https://wiki.ubuntu.com/DiegoTurcios
--
Recuerden Dios siempre esta presente:
http://sagradocorazondejesus-diegotc.blogspot.com/
ATT1..txt

___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Is there a Try and Catch method in QT

2010-06-30 Thread Coda Highland
I know this is the wrong mailing list but I will caution that Qt is
not exception-safe (and doesn't even have to be compiled with
exception support enabled) and throwing exceptions through Qt code
(for instance, in a slot or in an event handler) has negative effects.
It's possible to safely use exceptions (QtConcurrent uses them
internally for instance) but you need to make sure to catch them
before it crosses Qt code.

/s/ Adam

On Wed, Jun 30, 2010 at 8:05 PM, Carter, Nathan ncar...@bentley.edu wrote:

 This is actually the Qt-creator mailing list, not the Qt mailing list.  But
 I'll answer your question anyway.  In the future, though, ask Qt questions
 over there.  (It's called qt-interest and shows up if you search for that
 term.)
 The QString::toDouble() method does not throw an exception if it gets text
 that's not a double.  Instead, it has the ok parameter to let you know
 that information.  See the documentation (inside Qt-creator!) for
 QString::toDouble() to see how to use the ok parameter to do your test,
 instead of try-catch.
 But yes, the very fact that your code compiled tells you that C++ (and hence
 Qt) support try-catch structures.
 Nathan


 On Jun 30, 2010, at 9:01 PM, Diego Turcios wrote:

 Hi guys
 I thinks this is the right mailing list for my doubt.
 I am working on a small application in QT. But right now I have the
 following problem.
 I have a line edit, and I want to manipulate the values so only numbers
 (doubles) can be written on this line edit.
 I was trying something like this


 double quantity;
  try
     {
     quantity=ui-LEPrecio-text().toDouble();
  }
     catch(QString error)
     {
     QMessageBox msgBox;
     msgBox.setText(error);
     msgBox.exec();
     }
 After doing this. I am planning to manipulate the double value, but this
 doesn't work. If I write hello world on the line edit. Supposly it converts
 it, and it doesn't work. Any idea ;)

 Diego Turcios
 DiegoTc
 Ubuntu User  # 27518
 ---
 Mis Blogs
 http://diegoturcios.wordpress.com/
 https://wiki.ubuntu.com/DiegoTurcios
 --
 Recuerden Dios siempre esta presente:
 http://sagradocorazondejesus-diegotc.blogspot.com/
 ATT1..txt

 ___
 Qt-creator mailing list
 Qt-creator@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-creator



___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Is there a Try and Catch method in QT

2010-06-30 Thread Coda Highland
One last comment -- toDouble() takes a bool* parameter to indicate
success or failure; as mentioned, Qt (except for Concurrent) doesn't
use exceptions.

/s/ Adam

On Wed, Jun 30, 2010 at 8:01 PM, Diego Turcios diegoturcio...@gmail.com wrote:
 Hi guys
 I thinks this is the right mailing list for my doubt.
 I am working on a small application in QT. But right now I have the
 following problem.
 I have a line edit, and I want to manipulate the values so only numbers
 (doubles) can be written on this line edit.
 I was trying something like this


 double quantity;
  try
     {
     quantity=ui-LEPrecio-text().toDouble();
  }
     catch(QString error)
     {
     QMessageBox msgBox;
     msgBox.setText(error);
     msgBox.exec();
     }
 After doing this. I am planning to manipulate the double value, but this
 doesn't work. If I write hello world on the line edit. Supposly it converts
 it, and it doesn't work. Any idea ;)

 Diego Turcios
 DiegoTc
 Ubuntu User  # 27518
 ---
 Mis Blogs
 http://diegoturcios.wordpress.com/
 https://wiki.ubuntu.com/DiegoTurcios
 --
 Recuerden Dios siempre esta presente:
 http://sagradocorazondejesus-diegotc.blogspot.com/

 ___
 Qt-creator mailing list
 Qt-creator@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-creator



___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator