Search Results

Search found 139 results on 6 pages for 'yan zhou'.

Page 5/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • Is it safe to draw three separate QImages in three separate QThreads?

    - by yan bellavance
    I have a QMainWindow with three widgets inside that are promoted to a class containing a subclassed QThread. They each draw on a local QImage in their rexpective qthread which is sent with a signal once its drawn and then rendered by calling update (mandlebrot example) from the slot. Is this safe or dangerous? They do not share any data, at least none that I am generating and am wondering what data they could be sharing that is outside of my coding range ie that is generated by Qt automatically.

    Read the article

  • Is this the intention behavior in JComboBox? How I can avoid this behavior?

    - by Yan Cheng CHEOK
    I realize that if you are having a same selection in JComboBox, using up/down arrow key, will not help you to navigate the selection around. How I can avoid this behavior? See the below screen shoot /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * NewJFrame.java * * Created on May 8, 2010, 7:46:28 PM */ package javaapplication26; /** * * @author yccheok */ public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */ public NewJFrame() { initComponents(); /* If you are having 3 same strings here. Using, up/down arrow key, * will not move the selection around. */ this.jComboBox1.addItem("Intel"); this.jComboBox1.addItem("Intel"); this.jComboBox1.addItem("Intel"); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jComboBox1 = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jComboBox1.setEditable(true); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(105, 105, 105) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(137, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(63, 63, 63) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(217, Short.MAX_VALUE)) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JComboBox jComboBox1; // End of variables declaration }

    Read the article

  • Use Margin Auto and Center to center Float Left Div

    - by Yan Cheng CHEOK
    I know this question had been asked many times. http://stackoverflow.com/questions/1740587/float-a-div-to-center However, I follow their suggestion : <center> <div style="margin : auto"> <a href="#" style="float: left; margin-right: 10px;">Menu Item 1</a> <a href="#" style="float: left; margin-right: 10px;">Menu Item 2</a> <a href="#" style="float: left; margin-right: 10px;">Menu Item 3</a> </div> </center> By using "Center" and "Margin Auto", I still unable to center the menu item.

    Read the article

  • Difference among STLPort and SGI STL

    - by Yan Cheng CHEOK
    Recently, I was buzzed by the following problem STL std::string class causes crashes and memory corruption on multi-processor machines while using VC6. I plan to use an alternative STL libraries instead of the one provided by VC6. I came across 2 libraries : STLPort and SGI STL I was wondering what is the difference between the 2. Which one I should use? Which one able to guarantee thread safety? Thanks.

    Read the article

  • xstream handles non-english character

    - by Yan Cheng CHEOK
    I have the following code : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworld; import com.thoughtworks.xstream.XStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import javax.swing.JOptionPane; /** * * @author yccheok */ public class Test { @SuppressWarnings("unchecked") public static <A> A fromXML(Class c, File file) { XStream xStream = new XStream(); InputStream inputStream = null; try { inputStream = new java.io.FileInputStream(file); Object object = xStream.fromXML(inputStream); if (c.isInstance(object)) { return (A)object; } } catch (Exception exp) { exp.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); inputStream = null; } catch (java.io.IOException exp) { exp.printStackTrace(); return null; } } } return null; } @SuppressWarnings("unchecked") public static <A> A fromXML(Class c, String filePath) { return (A)fromXML(c, new File(filePath)); } public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; try { outputStream = new FileOutputStream(file); xStream.toXML(object, outputStream); } catch (Exception exp) { exp.printStackTrace(); return false; } finally { if (outputStream != null) { try { outputStream.close(); outputStream = null; } catch (java.io.IOException exp) { exp.printStackTrace(); return false; } } } return true; } public static boolean toXML(Object object, String filePath) { return toXML(object, new File(filePath)); } public static void main(String args[]) { String s = "\u6210\u4EA4\u91CF"; // print ??? System.out.println(s); // fine! show ??? JOptionPane.showMessageDialog(null, s); toXML(s, "C:\\A.XML"); String o = fromXML(String.class, "C:\\A.XML"); // show ??? JOptionPane.showMessageDialog(null, o); } } I run the following code through command prompt in Windows Vista. 1) May I know why System.out.println unable to print out Chinese Character in console? 2) I open up the xstream file. The saved value is <string>???</string> How can I make xstream save Chinese Character correctly? Thanks.

    Read the article

  • C++ Static Initializer - Is it thread safe

    - by Yan Cheng CHEOK
    Usually, when I try to initialize a static variable class Test2 { public: static vector<string> stringList; private: static bool __init; static bool init() { stringList.push_back("string1"); stringList.push_back("string2"); stringList.push_back("string3"); return true; } }; // Implement vector<string> Test2::stringList; bool Test2::__init = Test2::init(); Is the following code thread safe, during static variable initialization? Is there any better way to static initialize stringlist, instead of using a seperate static function (init)?

    Read the article

  • Various way to stop a thread - which is the correct way

    - by Yan Cheng CHEOK
    I had came across different suggestion of stopping a thread. May I know, which is the correct way? Or it depends? Using Thread Variable http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html private volatile Thread blinker; public void stop() { blinker = null; } public void run() { Thread thisThread = Thread.currentThread(); while (blinker == thisThread) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } } Using boolean flag private volatile boolean flag; public void stop() { flag = false; } public void run() { while (flag) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } } Using Thread Variable together with interrupt private volatile Thread blinker; public void stop() { blinker.interrupt(); blinker = null; } public void run() { Thread thisThread = Thread.currentThread(); while (!thisThread.isInterrupted() && blinker == thisThread) { try { thisThread.sleep(interval); } catch (InterruptedException e){ } repaint(); } }

    Read the article

  • How can I set where a Qt app finds a Qt module?

    - by yan bellavance
    I would like to include libQtGui.so.4 libQtNetwork.so.4 and libQtCore.so.4 in the same directory as where my app resides. How would I make Qt understand this? y purpose is to have a standalone app that uses shared libraries update: im gonna try to first remove them with QT-=gui etc and seeif I can add mine back after

    Read the article

  • Why can't we have an immutable version of operator[] for map

    - by Yan Cheng CHEOK
    The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i = m[0]; But not the following code : // error C2678: binary '[' : no operator... const std::map<int, int>& m = std::map<int, int>(); int i = m[0]; Most of the time, I prefer to make most of my stuff to become immutable, due to reason : http://www.javapractices.com/topic/TopicAction.do?Id=29 I look at map source code. It has mapped_type& operator[](const key_type& _Keyval) Is there any reason, why std::map unable to provide const mapped_type& operator[](const key_type& _Keyval) const

    Read the article

  • Is this a correct way to stop Execution Task

    - by Yan Cheng CHEOK
    I came across code to stop execution's task. private final ExecutorService executor = Executors.newSingleThreadExecutor(); public void stop() { executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (!Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; } I realize that, it is possible for Runnable to be in forever loop, as Unknown fun may Thread.sleep, clear the interrupt flag and ignore the InterruptedException Unknown fun may Thread.interrupted, clear the interrupt flag. I was wondering, is the following way correct way to fix the code? private final ExecutorService executor = Executors.newSingleThreadExecutor(); private volatile boolean flag = true; public void stop() { flag = false; executor.shutdownNow(); try { executor.awaitTermination(100, TimeUnit.DAYS); } catch (InterruptedException ex) { log.error(null, ex); } } public Runnable getRunnable() { return new Runnable() { public void run() { while (flag && !Thread.currentThread().isInterrupted()) { // What if inside fun(), someone try to clear the interrupt flag? // Say, through Thread.interrupted(). We will stuck in this loop // forever. fun(); } } }; }

    Read the article

  • Complete list of Fonts which support

    - by Yan Cheng CHEOK
    Currently, if I change the locale setting of my application by Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.SIMPLIFIED_CHINESE); What I understand from this JFreeChart forum is that, I am not using correct font. Once you get the reference of the LegentTitle, you can set it to any font. Apparently, JFreeChart's default is "Tahoma" and it doesn't support Chinese characters. May I know, how I can programmatic determine, as list of available Fonts in my system, which support Chinese? I can hard code it to Serif (It fully support Chinese, doesn't it?), its look n feel doesn't looks good to me. I would like to have more choices.

    Read the article

  • qapps runs well but breakpoint sometimes generates segmentation fault

    - by yan bellavance
    I have a qApp that generates a segmentation fault only when a breakpoint is inserted in the code (I can put it at different places) and only after 4-5 breakpoint stops. Do I have a problem with my code or is this a DBG bug. the method is part of a QThread Class. Basically what I did is i took the mandlebrot example, and have 3 instances of it in my program. So the program would look like a mainwindow that has 3 mandlebrot widgets in it, one besides the other. Is it possible that GDB doesnt support debugging qthread subclasses that are instantiated multiple times or is it thread-unsafe to do so. I dont have any problems at run-time.

    Read the article

  • Is It Safe to Cast Away volatile?

    - by Yan Cheng CHEOK
    Most of the time, I am doing this way. class a { public: ~ a() { i = 100; // OK delete (int *)j; // Compiler happy. But, is it safe? // Error : delete j; } private: volatile int i; volatile int *j; }; int main() { a aa; } However, I saw an article here: https://www.securecoding.cert.org/confluence/display/seccode/EXP32-C.+Do+not+access+a+volatile+object+through+a+non-volatile+reference Casting away volatile allows access to an object through a non-volatile reference. This can result in undefined and perhaps unintended program behavior. So, what will be the workaround for my above code example?

    Read the article

  • Java Font Display Problem

    - by Yan Cheng CHEOK
    I realize that, in my certain customer side, when I use the font provided by Graphics2D itself, and decrease the size by 1, it cannot display properly. private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) { if (MainFrame.getInstance().getJStockOptions().getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) { return; } final Font oldFont = g2.getFont(); final Font paramFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize()); final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = new Font(oldFont.getFontName(), oldFont.getStyle() | Font.BOLD, oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); /* * This date font cannot be displayed properly. Why? */ final Font dateFont = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); Rest of the font is OK. Here is the screen shoot (See the yellow box. There are 3 type of different font within the yellow box) :

    Read the article

  • Is there any need for me to use wstring in the following case

    - by Yan Cheng CHEOK
    Currently, I am developing an app for a China customer. China customer are mostly switch to GB2312 language in their OS encoding. I need to write a text file, which will be encoded using GB2312. I use std::ofstream file I compile my application under MBCS mode, not unicode. I use the following code, to convert CString to std::string, and write it to file using ofstream std::string Utils::ToString(CString& cString) { /* Will not work correctly, if we are compiled under unicode mode. */ return (LPCTSTR)cString; } To my surprise. It just works. I thought I need to at least make use of wstring. I try to do some investigation. Here is the MBCS.txt generated. I try to print a single character named ? (its value is 0xBDC5) When I use CString to carry this character, its length is 2. When I use Utils::ToString to perform conversion to std::string, the returned string length is 2. I write to file using std::ofstream My question is : When I exam MBCS.txt using a hex editor, the value is displayed as BD (LSB) and C5 (MSB). But I am using little endian machine. Isn't hex editor should show me C5 (LSB) and BD (MSB)? I check from wikipedia. GB2312 seems doesn't specific endianness. It seems that using std::string + CString just work fine for my case. May I know in what case, the above methodology will not work? and when I should start to use wstring?

    Read the article

  • Transferring binary file from web server to client

    - by Yan Cheng CHEOK
    Usually, when I want to transfer a web server text file to client, here is what I did import cgi print "Content-Type: text/plain" print "Content-Disposition: attachment; filename=TEST.txt" print filename = "C:\\TEST.TXT" f = open(filename, 'r') for line in f: print line Works very fine for ANSI file. However, say, I have a binary file a.exe (This file is in web server secret path, and user shall not have direct access to that directory path). I wish to use the similar method to transfer. How I can do so? What content-type I should use? Using print seems to have corrupted content received at client side. What is the correct method?

    Read the article

  • Is it possible to add a menu bar to a widget

    - by yan bellavance
    I would like to add a QMenuBar to a window of my program (not the QMainWindow) from QtDesigner but I do not see this widget in there and it seems the only way to do this from designer is to use a mainwindow. Would I absolutely need to create this QMenu by hand coding it. Is it possible/ok to instead add a QMainwindow that is actually declared inside my main QMainwindow?

    Read the article

  • SSL Not Working on other network

    - by Yan
    Hi I am running windows server 2003 standard and have installed the ssl cert for the company website . Attempting to access the website securely outside of our network the page does not load. Thanks in advance!

    Read the article

  • Should I use threeten instead of joda-time

    - by Yan Cheng CHEOK
    Hello all, I came across http://www.jroller.com/scolebourne/entry/why_jsr_310_isn_t. 1) I am currently migrating Java Calendar to joda-time. I was wondering, should I use threeten instead of joda-time? Is threeten production ready? 2) Can threeten library and joda-time libraries exist together in a same application? As I am using some 3rd parties libraries, which is using joda-time library too. 3) Will joda-time become an abandon project since there is threeten? Thanks.

    Read the article

  • Get ID of a clicked parent ID

    - by Yan Cheng CHEOK
    I try using evt.parent.attr("id") inside jsddm_close, but it doesn't work. <script type="text/javascript"> var ddmenuitem = 0; function jsddm_open() { // When "help-menu" being click, I will toggle drop down menu. ddmenuitem = $(this).find('ul').eq(0).toggle(); } function jsddm_close(evt) { // When everywhere in the document except "help-menu" being clicked, I will close the drop down menu. // How I can check everywhere in the document except "help-menu"? if (ddmenuitem) ddmenuitem.hide(); } $(document).ready(function() { $('#jsddm > li').bind('click', jsddm_open); $(this).bind('click', jsddm_close); }); </script> <ul id="jsddm"> <li><a href="#">Home</a></li> <li><a href="#" id="help-menu"><u>Help</u><small>xx</small></a> <ul> <li><a href="#">menu item 1</a></li> <li><a href="#">menu item 2</a></li> </ul> </li> </ul>

    Read the article

  • Any side effect of not using USES_CONVERSION

    - by Yan Cheng CHEOK
    Recently, I have a utilities function of // T2CA #include "ATLCONV.H" std::string Utils::CString2String(const CString& cString) { #if _MSC_VER > 1200 // Convert a TCHAR string to a LPCSTR // construct a std::string using the LPCSTR input CT2CA tmp(cString); std::string strStd (tmp); #else // Deprecated in VC2008. // construct a std::string using the LPCSTR input std::string strStd (T2CA (cString)); #endif return strStd; } I do several simple test it seems work fine. However, when I google around, I see most usage of T2CA in VC6, before they call, they will invoke USES_CONVERSION; Is there any thing I had missed out? Shall I invoke my function by : #else // Deprecated in VC2008. // construct a std::string using the LPCSTR input USES_CONVERSION; std::string strStd (T2CA (cString)); #endif

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >