Daily Archives

Articles indexed Sunday January 16 2011

Page 12/29 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • How do one improve him/her problem-solving ability ?

    - by gcc
    How can one improve him/her problem-solving ability? Every one says same thing "a real programmer knows how to handle real problem", but they forget how they learn this ability, or where (I know in school, no one gives us any ability, of course in my opinion). If you have any idea except above ones, feel free when you give your advice solve more problems do more exercises, write code, search google then write more ... For me, my question is like "Use complex/known library instead of using your own." In other words,t I want your presonal experience, book recommendation, web page on problem solving. Moreover, look your problem-solving method and give us your personal ability as if it is an algorithm

    Read the article

  • SSH main process ended

    - by Khaled
    I have a running ubuntu server 10.04.1. When I tried to login to the server via ssh, I could not. Instead, I got connection refused error. I tried to ping the machine and I got reply! So, the clear reason is that SSH daemon is stopped. After reboot, I was able to login to my server via ssh. After some time, I looked at my logs /var/log/syslog and found the following records: Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2465) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2469) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2473) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2477) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2481) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2485) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2489) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2493) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2497) terminated with status 255 Jan 16 10:57:09 myserver init: ssh main process ended, respawning Jan 16 10:57:09 myserver init: ssh main process (2501) terminated with status 255 Jan 16 10:57:09 myserver init: ssh respawning too fast, stopped I searched for a similar problem/solution. Some people said that this is caused by the SSH daemon trying to start before networking and they suggest to change ListenAddress in /etc/ssh/sshd_config to be 0.0.0.0. I think this is not the cause in my case, because my problem occurs after system is up and running. Any idea what is causing this? This is ubuntu server and it should be running and accessed remotely using ssh.

    Read the article

  • Command works partially when run from startup applications

    - by Gaurav Butola
    I have this script (or rather a set of commands which has permission to execute) to enable two finger scrolling and two finger tap = right click The script is located in /home/gaurav/Multigesture/multigesture. When I run the following command in terminal, two finger scrolling and two finger tap = right click start working. I have to run this command each time I boot my laptop. "/home/gaurav/Multigesture/multigesture" So I put this command in the startup applications so that I dont have to run the command each time I boot but when I reboot two finger scrolling is not working, only two finger tap = right click works. What could be the problem, If the command works fine from the terminal then how come it is working partially when i put it into startup applications. Here is the content of the script xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8 PS. the file which has all the commands (script's) name is multitouch

    Read the article

  • Atheros wireless not working

    - by Chandru1
    I have been struggling hard since i have installed Ubuntu 10.10 but it has been difficult for me to get my wifi working. So here is what i tried. First i checked whether i have the driver using the ifconfig command and it shows the wireless lan driver as wlan0. Next, i tried the command iwlist wlan0 scanning by becoming the root which gave me the output as no scan results. Next, i visited this link https://help.ubuntu.com/community/WifiDocs/Driver/Atheros to see as to what problem my laptop may have. I do own have an ath5k chipset. And as i followed the instructions in the above link in one of the blacklist-ath_pci.conf file had this written in it. For some Atheros 5K RF MACs, the madwifi driver loads buts fails to correctly initialize the hardware, leaving it in a state from which ath5k cannot recover. To prevent this condition, stop madwifi from loading by default. Use Jockey to select one driver or the other. (Ubuntu: #315056, #323830 I am not that good at Linux but i have given it a try. I am desperate to have my wifi working and i would be glad if this community could help. ADDED: If anyone would like to know as to what drivers i am using this is the output. network description: Wireless interface product: AR2413 802.11bg NIC vendor: Atheros Communications Inc. physical id: 3 bus info: pci@0000:0a:03.0 logical name: wlan0 version: 01 serial: 00:19:7d:d3:0c:fd width: 32 bits clock: 33MHz capabilities: pm bus_master cap_list ethernet physical wireless configuration: broadcast=yes driver=ath5k driverversion=2.6.35-24-generic firmware=N/A latency=168 link=no maxlatency=28 mingnt=10 multicast=yes wireless=IEEE 802.11bg resources: irq:18 memory:d0000000-d000ffff Some more information and output as to what i have done. lsmod | grep ath ath5k 130083 0 mac80211 231541 1 ath5k ath 8153 1 ath5k cfg80211 144470 3 ath5k,mac80211,ath led_class 2633 1 ath5k

    Read the article

  • layout problam in android

    - by mahdi
    Hi i try show layout like image 1 (textView and editText in same line) but my out put shown like image 2 ! i try with this code : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5px" > <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="URL:" android:layout_alignBaseline="@+id/entry" android:layout_alignParentLeft="true"/> /> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/label" android:layout_alignParentTop="true" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingRight="30px" android:paddingLeft="30px" android:text="Go..." /> </LinearLayout> please help me thanks

    Read the article

  • Why is there an implicit conversion from Float/Double to BigDecimal, but not from String?

    - by soc
    Although the situation of conversion from Doubles to BigDecimals has improved a bit compared to Java scala> new java.math.BigDecimal(0.2) res0: java.math.BigDecimal = 0.20000000000000001110223024625156... scala> BigDecimal(0.2) res1: scala.math.BigDecimal = 0.2 and things like val numbers: List[BigDecimal] = List(1.2, 3.2, 0.7, 0.8, 1.1) work really well, wouldn't it be reasonable to have an implicit conversion like implicit def String2BigDecimal(s: String) = BigDecimal(s) available by default which can convert Strings to BigDecimals like this? val numbers: List[BigDecimal] = List("1.2", "3.2", "0.7", "0.8", "1.1") Or am I missing something and Scala resolved all "problems" of Java with using the BigDecimal constructor with a floating point value instead of a String, and BigDecimal(String) is basically not needed anymore in Scala?

    Read the article

  • Pass a Message From Thread to Update UI

    - by Jay Dee
    Ive created a new thread for a file browser. The thread reads the contents of a directory. What I want to do is update the UI thread to draw a graphical representation of the files and folders. I know I can't update the UI from within a new thread so what I want to do is: whilst the file scanning thread iterates through a directories files and folders pass a file path string back to the UI thread. The handler in the UI thread then draws the graphical representation of the file passed back. public class New_Project extends Activity implements Runnable { private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Log.d("New Thread","Proccess Complete."); Intent intent = new Intent(); setResult(RESULT_OK, intent); finish(); } }; public void getFiles(){ //if (!XMLEFunctions.canReadExternal(this)) return; pd = ProgressDialog.show(this, "Reading Directory.", "Please Wait...", true, false); Log.d("New Thread","Called"); Thread thread = new Thread(this); thread.start(); } public void run() { Log.d("New Thread","Reading Files"); getFiles(); handler.sendEmptyMessage(0); } public void getFiles() { for (int i=0;i<=allFiles.length-1;i++){ //I WANT TO PASS THE FILE PATH BACK TU A HANDLER IN THE UI //SO IT CAN BE DRAWN. **passFilePathBackToBeDrawn(allFiles[i].toString());** } } }

    Read the article

  • How to throw meaningful data in exceptions ?

    - by ZeroCool
    I would like to throw exceptions with meaningful explanation ! I thought of using variable arguments worked fine but lately I figured out it's impossible to extend the class in order to implement other exception types. So I figured out using an std::ostreamstring as a an internal buffer to deal with formatting ... but doesn't compile! I guess it has something to deal with copy constructors. Anyhow here is my piece of code: class Exception: public std::exception { public: Exception(const char *fmt, ...); Exception(const char *fname, const char *funcname, int line, const char *fmt, ...); //std::ostringstream &Get() { return os_ ; } ~Exception() throw(); virtual const char *what() const throw(); protected: char err_msg_[ERRBUFSIZ]; //std::ostringstream os_; }; The variable argumens constructor can't be inherited from! this is why I thought of std::ostringstream! Any advice on how to implement such approach ?

    Read the article

  • How to extract data from F# list

    - by David White
    Following up my previous question, I'm slowly getting the hang of FParsec (though I do find it particularly hard to grok). My next newbie F# question is, how do I extract data from the list the parser creates? For example, I loaded the sample code from the previous question into a module called Parser.fs, and added a very simple unit test in a separate module (with the appropriate references). I'm using XUnit: open Xunit [<Fact>] let Parse_1_ShouldReturnListContaining1 () = let interim = Parser.parse("1") Assert.False(List.isEmpty(interim)) let head = interim.Head // I realise that I have only one item in the list this time Assert.Equal("1", ???) Interactively, when I execute parse "1" the response is: val it : Element list = [Number "1"] and by tweaking the list of valid operators, I can run parse "1+1" to get: val it : Element list = [Number "1"; Operator "+"; Number "1"] What do I need to put in place of my ??? in the snippet above? And how do I check that it is a Number, rather than an Operator, etc.?

    Read the article

  • WPF WebBrowser: How to set element click event?

    - by Ralph
    I've figured out how to make everything red as soon as the page is finished loading: private void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e) { var doc = (IHTMLDocument2)webBrowser1.Document; foreach (IHTMLElement elem in doc.all) { elem.style.backgroundColor = "#ff0000"; } } Now what if I want to make the element only change color when it's clicked? I see that elem has an onclick property, but it's type is dynamic so I don't know what to do with it. The documentation is pretty useless.

    Read the article

  • Make object by it's name

    - by Ockonal
    Hello, is it possible to return exemplar of object using passed type name (string) in c++? I have some base abstract class Base and a few derivates. Example code: class Base { /* ... */ }; class Der1 : public Base { /* ... */ }; class Der2 : public Base { /* ... */ }; And I need function like: Base *objectByType(const std::string &name); Number of derivates classes are changeable and I don't want to make something like switching of name and returning by hands new object type. Is it possible in c++ to do that automatically anyway? p.s. usage should looks like: dynamic_cast<Der1>(objectByType("Der1")); I need pure c++ code (crossplatform). Using boost is permissible.

    Read the article

  • Is there a browser independet bookmarktool supporting tags, date and free comments?

    - by bernd_k
    I am looking for a tool, which helps me to organize my personal bookmarks. I want to be able to assign tags and free comments to a bookmark. I want to search my bookmarks by tags date of bookmarking pattern in title pattern in url It would be nice to be web based to enable sharing my bookmarks between different machines. But for it would be OK, if it works on a single machine as long as it has some import/export way to transfer the links to a new machine replacing the old. As browsers I'm using Firefox and ChromePlus. It would be nice, if the solution works with both browsers. With free comments, I mean additional remarks stored for a bookmark, which is not essential for searching.

    Read the article

  • Populating a GridView with ImageViews dynamically/programmatically using a ImageAdapter

    - by Julian Vogels
    Hi folks, this is my first question at stackoverflow, but it's a little tricky already... I try to develop an Android App which allows the user to fetch data from flickr and show it in a gridview (with some nice 3D-Animation). After some adventures i got it almost running, but now I'm stuck. Here's the problem: I got a UI Thread "LoadPhotosTask" which gets the pictures from flickr, just like the open source application photostream. In the method onProgressUpdate(LoadedPhoto... value) of that subclass I call addPhoto(). Until now everythings fine - I got some nice Bitmap and Flickr.photo data with all the information I need. @Override public void onProgressUpdate(LoadedPhoto... value) { addPhoto(value); } On the other hand I have got a GridView. Now I want to fill it with the Photos. It has got an adapter called ImageAdapter (which extends BaseAdapter, see this tutorial). If I use an array inside the ImageAdapter class I can populate the GridView with some sample images. But if I want to populate it at runtime, I don't know what to do. How do I have to set up the getView method in the ImageAdapter? I was trying to fill the array inside the ImageAdapter class with my values in addPhoto, but it doesn't display anything. So first of all I was setting up the array with the amount of Photos i wanted to display in the grid like that (code is inside the ImageAdapter class): // class variable private ImageView[] mThumbIds; [...] public void setupArray(int count) { this.mThumbIds = new ImageView[count]; } Then I call this method with the lenght of my photolist: final Flickr.PhotoList list = params[0]; final int count = list.getCount(); int helper = 0; imagead.setupArray(count); Afterwards I call the getView method manually inside the addPhoto method: private void addPhoto(LoadedPhoto... value) { ImageView image = (ImageView) mInflater.inflate( R.layout.grid_item_photo, null); image.setImageBitmap(value[0].mBitmap); image.setTag(value[0].mPhoto); imagead.setmThumbIds(image, value[0].mPosition); imagead.getView(value[0].mPosition, null, mpicturesGrid); } That is the getView method inside ImageAdapter: public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // if it's not recycled, initialize some // attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(EDGE_LENGTH, EDGE_LENGTH)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(0, 0, 0, 0); imageView.setVisibility(View.VISIBLE); } else { imageView = (ImageView) convertView; } imageView.setImageDrawable(mThumbIds[position].getDrawable()); imageView.setTag(mThumbIds[position].getTag()); return imageView; } Ok, finally I apologize for my poor english and I hope you can give me some help with the information I provided. Greetings, Julian

    Read the article

  • Trying to understand the usage of class_eval

    - by eMxyzptlk
    Hello everyone, I'm using the rails-settings gem, and I'm trying to understand how you add functions to ActiveRecord classes (I'm building my own library for card games), and I noticed that this gem uses one of the Meta-programming techniques to add the function to the ActiveRecord::Base class (I'm far from Meta-programming master in ruby, but I'm trying to learn it) module RailsSettings class Railtie < Rails::Railtie initializer 'rails_settings.initialize', :after => :after_initialize do Railtie.extend_active_record end end class Railtie def self.extend_active_record ActiveRecord::Base.class_eval do def self.has_settings class_eval do def settings RailsSettings::ScopedSettings.for_thing(self) end scope :with_settings, :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}')", :select => "DISTINCT #{self.table_name}.*" scope :with_settings_for, lambda { |var| { :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}') AND settings.var = '#{var}'" } } scope :without_settings, :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}')", :conditions => 'settings.id IS NULL' scope :without_settings_for, lambda { |var| { :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}') AND settings.var = '#{var}'", :conditions => 'settings.id IS NULL' } } end end end end end end What I don't understand is why he uses class_eval on ActiveRecord::Base, wasn't it easier if he just open the ActiveRecord::Base class and define the functions? Specially that there's nothing dynamic in the block (What I mean by dynamic is when you do class_eval or instance_eval on a string containing variables) something like this: module ActiveRecord class Base def self.has_settings class_eval do def settings RailsSettings::ScopedSettings.for_thing(self) end scope :with_settings, :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}')", :select => "DISTINCT #{self.table_name}.*" scope :with_settings_for, lambda { |var| { :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}') AND settings.var = '#{var}'" } } scope :without_settings, :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}')", :conditions => 'settings.id IS NULL' scope :without_settings_for, lambda { |var| { :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND settings.thing_type = '#{self.base_class.name}') AND settings.var = '#{var}'", :conditions => 'settings.id IS NULL' } } end end end end I understand the second class_eval (before the def settings) is to define functions on the fly on every class that 'has_settings' right ? Same question here, I think he could use "def self.settings" instead of "class_eval.... def settings", no ?

    Read the article

  • Long numbers. Division.

    - by user577395
    Hello, world! I have a problem. Today I tried to create a code, which finds Catalan number. But in my program can be long numbers. I found numerator and denominator. But i can't div long numbers! Also, only standard libraries was must use in this program. Help me please. This is my code #include <vector> #include <iostream> using namespace std; int main(int argc, char *argv[]) { const int base = 1000*1000*1000; vector <int> a, b; int n, carry = 0; cin>>n; a.push_back(n); for (int ii=n+2; ii!=(2*n)+1;++ii) { carry = 0; for (size_t i=0; i<a.size() || carry; ++i) { if (i == a.size()) a.push_back (0); long long cur = carry + a[i] * 1ll * ii; a[i] = int (cur % base); carry = int (cur / base); } } while (a.size() > 1 && a.back() == 0) a.pop_back(); b.push_back(n); for (int ii=1; ii!=n+1;++ii) { carry = 0; for (size_t i=0; i<b.size() || carry; ++i) { if (i == b.size()) b.push_back (0); long long cur = carry + b[i] * 1ll * ii; b[i] = int (cur % base); carry = int (cur / base); } } while (b.size() > 1 && b.back() == 0) b.pop_back(); cout<<(a.empty() ? 0 : a.back()); for (int i=(int)a.size()-2; i>=0; --i) cout<<(a[i]); cout<<" "; cout<<(b.empty() ? 0 : b.back()); for (int i=(int)b.size()-2; i>=0; --i) cout<<(b[i]); //system("PAUSE"); cout<<endl; return 0; } P.S. Sorry for my bad english =)

    Read the article

  • crystal report problem

    - by Baharanji
    Dear all, I have a Table which Contains items and its prices and those prices some in Dollars and the rest in pounds and the items are divided into sections and I want to use a modified Sum function in the Crystal Report so as to show at the end of each group the total in pounds like that in C# int price=0; foreach (item it in items) { if (it.curr=="$") { price+=it.price*DollarPrice } else price+=it.price; } return price; That's exactly what i want to do in crystal reports but i dont have any clue how to do so So if you have any Idea please help me, Regards, Baher.

    Read the article

  • store image in sqlite

    - by bbkaaka
    i have the folloing code : final Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(new ImageAdapter(this)); g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Bitmap b = null; b=BitmapFactory.decodeResource(getResources(),*********); b.compress(CompressFormat.PNG, 0, outputStream); AlertDialog.Builder builder = new AlertDialog.Builder(Edit.this); builder.setTitle("Comfirm"); builder.setMessage("Do you want to choose this picture?"); builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { image = outputStream.toByteArray(); } }); you see * which need type int like android.R.drawble.icon. i want to store the picture when users click to picture how can i get the picture

    Read the article

  • iPhone - extending a class delegate

    - by Digital Robot
    OK, I know how to create a class extension, using something like that: on .h @interface UIButton (myExtensionName) // my extended methods @end and then on .m @implementation UIButton (myExtensionName) // my implementations @end But how do I declare the extended delegates I may create? If this was a normal class I would do @protocol myExtensionName <NSObject> // my delegate declarations @end but how do I do that on a class extension? thanks

    Read the article

  • PPTP VPN connection always connects successfully in Mac OS X/windows but drops after 2 minute in iPad or it doesn't connect al all!

    - by Farshid
    Dear Users, I've a big problem with using iPad's VPN connection. When I use the same VPN connection (PPTP) configuration parameters in my Mac OS X Snow Leopard or my windows XP (Bootcamp), it works flawlessly but when I define the same connection in my iPad, connection drops in about 1 or 2 minutes (some times) and most of the time, it Doesn't Connect at all. I'm using iPad 3G with iOS 4.2.1 and my iPad is not jail-broken. I've tried so hard to make it work in an stable manner but not found any solution yet. (I should have put encryption level to No-Encryption in Mac and Windows otherwise it won't connect in my desktop operating systems. It is a host-related issue and I'm binding to that). I'm sure there is no technical problem in my iPad's hardware and this problem also exists in my friend's iPad too. Our devices work perfectly with 3G and Wifi connections. Your answers are really appreciated.

    Read the article

  • Adding/removing session variables on Page OnInit/OnLoad in C#

    - by MKS
    Hi Guys, I am using C#. I am having below code in C#: protected override void OnInit(EventArgs e) { try { if (Session["boolSignOn"].ToString() == "true".ToString()) { lblPanelOpen.Text = Session["panelOpen"].ToString(); } else { lblPanelOpen.Text = Session["panelOpen"].ToString(); } } catch (Exception ex) { Logger.Error("Error processing request:" + ex.Message); } } protected override void OnLoad(EventArgs e) { try { if (!string.IsNullOrEmpty(Session["panelOpen"].ToString())) { lblPanelOpen.Text = string.Empty; Session.Remove("panelOpen"); } } catch (Exception ex) { Logger.Error("Unable to remove the session variable:" + ex.Message); } } In above code I am having a Session["panelOpen"] variable which is created from another user control and once my page is trying to render, I am storing Session["panelOpen"] in my hidden lblPanelOpen.Text on page OnInit() method, however when page is loaded completely then I am trying to remove the session variable. Please suggest!

    Read the article

  • How to load mht from stream/string into a WebBrowser control?

    - by Sameh Serag
    The WebBrowser control loads properly any mht file if I use the Navigate method, but when I use the DocumentText or DocumentStream properties, the source of the mht file is displayed as if I opened the file in notepad. If I write the stream to a temp file then Navigate to it, it works properly, but I don't want to do it this way. This issue seems common, but I didn't find a working solution for it. Some people suggest I should fool IE by implementing IPersistMoniker com interface, ...etc. I have tried with this a little bit, but unfortunately I got the same result. May be I have done something wrong. I still feel their should be a more straightforward solution (other than saving in a temp file first), any idea?

    Read the article

  • Trouble getting QMainWindow to scroll

    - by random
    A minimal example: class MainWindow(QtGui.QMainWindow): def __init__(self, parent = None): QtGui.QMainWindow.__init__(self, parent) winWidth = 683 winHeight = 784 screen = QtGui.QDesktopWidget().availableGeometry() screenCenterX = (screen.width() - winWidth) / 2 screenCenterY = (screen.height() - winHeight) / 2 self.setGeometry(screenCenterX, screenCenterY, winWidth, winHeight) layout = QtGui.QVBoxLayout() layout.addWidget(FormA()) mainWidget = QtGui.QWidget() mainWidget.setLayout(layout) self.setCentralWidget(mainWidget) FormA is a QFrame with a VBoxLayout that can expand to an arbitrary number of entries. In the code posted above, if the entries in the forms can't fit in the window then the window itself grows. I'd prefer for the window to become scrollable. I've also tried the following... replacing mainWidget = QtGui.QWidget() mainWidget.setLayout(layout) self.setCentralWidget(mainWidget) with mainWidget = QtGui.QScrollArea() mainWidget.setLayout(layout) self.setCentralWidget(mainWidget) results in the forms and entries shrinking if they can't fit in the window. Replacing it with mainWidget = QtGui.QWidget() mainWidget.setLayout(layout) scrollWidget = QtGui.QScrollArea() scrollWidget.setWidget(mainWidget) self.setCentralWidget(scrollWidget) results in the mainwidget (composed of the forms) being scrunched in the top left corner of the window, leaving large blank areas on the right and bottom of it, and still isn't scrollable. I can't set a limit on the size of the window because I wish for it to be resizable. How can I make this window scrollable?

    Read the article

  • Memory management in iOS

    - by angrest
    Looks like I did not understand memory management in Objective C... sigh. I have the following code (note that in my case, placemark.thoroughfare and placemark.subThoroughfare are both filled with valid data, thus both if-conditions will be TRUE if (placemark.thoroughfare) { [item.place release]; item.place = [NSString stringWithFormat:@"%@ ", placemark.thoroughfare]; } else { [item.place release]; item.place = @"Unknown Place"; } if (placemark.thoroughfare && placemark.subThoroughfare) { // *** problem is here *** [item.place release]; item.place = [NSString stringWithFormat:@"%@ %@", placemark.thoroughfare , placemark.subThoroughfare]; } If I do not release item.place at the marked location in the code, Instruments finds a memory leak there. If I do, the program crashes as soon as I try to access item.place outside the offending method. Any ideas?

    Read the article

  • UTF-8 to Unicode conversion

    - by sandeep
    Hi, I am having problems with converting UTF-8 to Unicode. Below is the code: int charset_convert( char * string, char * to_string,char* charset_from, char* charset_to) { char *from_buf, *to_buf, *pointer; size_t inbytesleft, outbytesleft, ret; size_t TotalLen; iconv_t cd; if (!charset_from || !charset_to || !string) /* sanity check */ return -1; if (strlen(string) < 1) return 0; /* we are done, nothing to convert */ cd = iconv_open(charset_to, charset_from); /* Did I succeed in getting a conversion descriptor ? */ if (cd == (iconv_t)(-1)) { /* I guess not */ printf("Failed to convert string from %s to %s ", charset_from, charset_to); return -1; } from_buf = string; inbytesleft = strlen(string); /* allocate max sized buffer, assuming target encoding may be 4 byte unicode */ outbytesleft = inbytesleft *4 ; pointer = to_buf = (char *)malloc(outbytesleft); memset(to_buf,0,outbytesleft); memset(pointer,0,outbytesleft); ret = iconv(cd, &from_buf, &inbytesleft, &pointer, &outbytesleft);ing memcpy(to_string,to_buf,(pointer-to_buf); } main(): int main() { char UTF []= {'A', 'B'}; char Unicode[1024]= {0}; char* ptr; int x=0; iconv_t cd; charset_convert(UTF,Unicode,"UTF-8","UNICODE"); ptr = Unicode; while(*ptr != '\0') { printf("Unicode %x \n",*ptr); ptr++; } return 0; } It should give A and B but i am getting: ffffffff fffffffe 41 Thanks, Sandeep

    Read the article

  • 'Fixed' for loop - what is more efficient?

    - by pimvdb
    I'm creating a tic-tac-toe game, and one of the functions has to iterate through each of the 9 fields (tic-tac-toe is played on a 3x3 grid). I was wondering what is more efficient (which one is perhaps faster, or what is the preferred way of scripting in such situation) - using two for nested loops like this: for(var i=0; i<3; i++) { for(var j=0; j<3; j++) { checkField(i, j); } } or hard-coding it like this: checkField(0, 0); checkField(0, 1); checkField(0, 2); checkField(1, 0); checkField(1, 1); checkField(1, 2); checkField(2, 0); checkField(2, 1); checkField(2, 2); As there are only 9 combinations, it would be perhaps overkill to use two nested for loops, but then again this is clearer to read. The for loop, however, will increment variables and check whether i and j are smaller than 3 every time as well. In this example, the time saving at least might be negligible, but what is the preferred way of coding in this case? Thanks.

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >