In 1644, the Manchus took over China and founded the Qing dynasty. The Qing weren't the worst rulers; under them the arts flowered and culture bloomed. Moreover, they attempted to copy Chinese institutions and philosophy to a much greater extent than then the Mongols of the Yuan. However, in their attempt to to emulate the Chinese, they were even more conservative and inflexible than the Ming. Their approach to foreign policy, which was to make everyone treat the Emperor like the Son of Heaven and not acknowledge other countries as being equal to China, didn't rub the West the right way, even when the Chinese were in the moral right (as in the Opium Wars, which netted Britain Hong Kong and Kowloon). To live during the Qing Dynasty was to live in interesting times.
Most importantly, the Western world attempted to make contact on a government-to-government basis, and, at least initially, failed. The Chinese (more specifically, the ultra-conservative Manchus) had no room in their world-view for the idea of independent, equal nations (this viewpoint, to a certain degree, still persists today). There was the rest of the world, and then there was China. It wasn't that they rejected the idea of a community of nations; it's that they couldn't conceive of it. It would be like trying to teach a Buddhist monk about the Father, Son, and the Holy Ghost. This viewpoint was so pervasive that Chinese reformers who advocated more flexibility in China's dealings with the West were often accused of being Westerners with Chinese faces.
Other problems that plagued the late (1840 onwards) Qing included rampant corruption, a steady decentralization of power, and the unfortunate fact that they were losing control on too many fronts at the same time. Rebellions sprouted like mushrooms after a rain; apocalyptic cults undermined what little official authority remained. Several of the rebellions, such as the Taiping Rebellion, very nearly succeeded. Compounding the problems was squabbling between various reformers who disagreed on how to best combat the chaos and the West (not necessarily in that order); in hindsight, it is clear that the entire system was slowly collapsing... The attitude of the Western powers towards China (England, Russia, Germany, France, and the United States, were, more or less, the primary players) was strangely ambivalent.
On the one hand, they did their best to undermine what they considered to be restrictive trading and governmental regulations; the best (or worst, depending on your point of view) example of that was the British smuggling of opium into Southern China. Other examples included the 'right' for foreign navies to sail up Chinese rivers and waterways, and extra-territoriality, which meant that if a British citizen committed a crime in Qing China, he would be tried in a British council under British law. Most of these 'rights' came into being under a series of treaties that came to be known, and rightly so, as the Unequal Treaties. On the other hand, they did do their best to prop up the ailing Qing, the most notable example being the crushing of the Boxer Rebellion in 1900 by foreign troops (primarily U. S.
Marines). What the Western powers were interested in was the carving up of China for their own purposes, and that, paradoxically, required keeping China together. But things happened to prevent that. First, in 1911, the Qing dynasty collapsed and China plunged headlong into chaos..